Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.Cazaea:materialish-progress:1.0.2'
}
dependencies {
implementation("com.github.Cazaea:materialish-progress:1.0.2")
}
<dependency>
<groupId>com.github.Cazaea</groupId>
<artifactId>materialish-progress</artifactId>
<version>1.0.2</version>
</dependency>
libraryDependencies += "com.github.Cazaea" % "materialish-progress" % "1.0.2"
:dependencies [[com.github.Cazaea/materialish-progress "1.0.2"]]
I needed to keep a consistent (or as close as possible) look in an app across all Android Versions. The progress wheel is quite cool in Lollipop, and pretty horrible on Gingerbread.
So I created this. This view uses Progress Wheel as a base, but has been almost completely rewritten (the original view uses handlers for updating the wheel).
This implementation tries to follow as close as possible the guidelines for the circular progress as described here.
This is how it looks in indeterminate mode (the spinSpeed here is 0.64 which is the default, look below how to change it):
And in determinate mode (here the spinSpeed is set to 0.333):
You can create your own progress wheel in xml like this (remeber to add
xmlns:wheel="http://schemas.android.com/apk/res-auto"
):
compile 'com.github.cazaea:materialish-progress:1.0.2'
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
<com.cazaea.materialishprogress.ProgressWheel
android:id="@+id/progress_wheel"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
wheel:matProg_barColor="#5588FF"
wheel:matProg_progressIndeterminate="true" />
Or in code:
ProgressWheel wheel = new ProgressWheel(context);
wheel.setBarColor(Color.BLUE);
...
Use
setCallback(ProgressCallback)
to assign a callback that will be called each time the progress changes. This way you can update a value on the progress alongside with the progress animation, or execute an action once the progress reaches a certain value. in the indeterminatge wheel, the callback is called with a value of -1.0f every time the animation cycle finishes (when the wheel shrinks back to its smaller size).
For making the wheel indeterminate, just call the
spin()
method. If you set a progress value, the wheel will stop spinning.You have two methods for setting the progress:
progressWheel.setProgress(float value)
Sets the value, and the wheel will smoothly animate to that value. The speed of the animation is defined by the spinSpeed (can be set with
setSpinSpeed
, which number is the number of full turns per second)
progressWheel.setInstantProgress(float value)
Sets the value, and the wheel will instantly move to that value.
You can change other wheel properties such as the progress bar color, the wheel's background or the wheel's size and width.
In case you want the spinning wheel to fill the whole layout instead of having a fixed size, you can use
matProg_fillRadius
.
<com.cazaea.materialishprogress.ProgressWheel
android:id="@+id/progress_wheel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
wheel:matProg_barColor="#5588FF"
wheel:matProg_progressIndeterminate="true"
wheel:matProg_fillRadius="true" />
This way, the wheel will be as big as the parent layout. Be warned though, if the parentlayout is not square, the wheel will become an oval since the wheel will always adapt to fill the parent view.
In the xml definition, besides the fillRadius property, you can set:
Copyright 2017 Cazaea
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.