Material-ish Progress


Source link: https://github.com/pnikosis/materialish-progress

![](https://img.shields.io/badge/Methods and size-106 | 12 KB-e91e63.svg)

Material-ish Progress

A material style progress wheel compatible with 2.3

Try the demo app on Google Play:

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 also have a linear determinate progress mode if you don't like the animation.

Download

You can copy the ProgressWheel.java (in the library module) and the attrs.xml content into your project. Or you can get the binaries from Maven central by adding in your build.gradle dependencies:

compile 'com.pnikosis:materialish-progress:1.7'

Usage

You can create your own progress wheel in xml like this (remeber to add xmlns:wheel="http://schemas.android.com/apk/res-auto"):

<com.pnikosis.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);
 ... 

Callback

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).

Indeterminate wheel

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.

Fill radius

In case you want the spinning wheel to fill the whole layout instead of having a fixed size, you can use matProg_fillRadius.

<com.pnikosis.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.

Other options

In the xml definition, besides the fillRadius property, you can set:

  • matProg_progressIndeterminate: boolean, if you want the wheel to spin right away.
  • matProg_barColor: color, sets the small bar's color (the spinning bar in the indeterminate wheel, or the progress bar)
  • matProg_barWidth: dimension, the width of the spinning bar
  • matProg_rimColor: color, the wheel's border color
  • matProg_rimWidth: dimension, the wheel's width (not the bar)
  • matProg_spinSpeed: float, the base speed for the bar in indeterminate mode, and the animation speed when setting a value on progress. The speed is in full turns per second, this means that if you set speed as 1.0, means that the bar will take one second to do a full turn.
  • matProg_barSpinCycleTime: integer, the time in milliseconds the indeterminate progress animation takes to complete (extending and shrinking the bar while spinning)
  • matProg_circleRadius: dimension, the radius of the progress wheel, it will be ignored if you set fillRadius to true
  • matProg_fillRadius: boolean, set to true if you want the progress wheel to fill the whole layout
  • matProg_linearProgress: boolean, set to true if you want a linear animation on the determinate progress (instead of the interpolated default one).

Versions

  • 1.0 Initial release
  • 1.1 The default speed is closer to the default progress wheel in Lollipop. Removed unused icons.
  • 1.2 Interpolated determinate progress, a new option to set a linear progress (which was the default before)
  • 1.3 Added a prefix to the attributes to avoid collisions, new callback called when the progress changes in the determinate wheel.
  • 1.4 Improved callback, now receives a value which is rounded to two decimals
  • 1.5 Callback is called with a value of -1.0f in the indeterminate wheel every time the animation cycle finishes, updated Gradle and support libraries
  • 1.7 Animations are disabled when the system preferences have disabled animations

License

Copyright 2014 Nico Hormazábal  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. 

Resources

An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

A Promise wrapper around RxJava's Observable. A promise represents a future value (usually of an asynchronous operation).

Postman is a java library that uses code generation to handle the details of implementing the Parcelable interface on Android.

Metajava is a collection of utilities that make writing annotation processors and code generation easier.

Rx utility for Realm database.

Android gradle plugin that adds text to all the debug launcher icons. That is useful for QA teams to know the version of the app that are testing.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes