Skip to content

bayan1987/circularView

Repository files navigation

CircularView

Android ArsenalMinimum SDK

A special shoutout to @carlossotelo for his suggestions on anti-aliasing solutions

Include in your project

In your root/build.gradle

allprojects{repositories{... maven{url 'https://jitpack.io' } } } 

In your app/build.gradle

dependencies{compile 'com.github.rjsvieira:circularView:1.3.0' }

Customization

CircleView allows you to customize its default fields for your personal use. The attribute list can be found within the attrs.xml file.

Below is the configuration for the circleView presented on the first gif

<rjsv.circularview.CircleView android:id="@+id/circle_view"circleview:layout_constraintTop_toTopOf="parent"circleview:layout_constraintBottom_toBottomOf="parent"circleview:layout_constraintStart_toStartOf="parent"circleview:layout_constraintEnd_toEndOf="parent"android:layout_width="500dp"android:layout_height="500dp"circleview:suffixEnabled="true"circleview:suffixValue="EUR"circleview:arcBorderColor="@color/color_arc"circleview:arcColor="@color/color_arc"circleview:arcHasBorder="false"circleview:arcWidth="15dp"circleview:hasIndicator="false"circleview:indicatorColor="@color/theme_red_primary"circleview:indicatorRadius="6"circleview:progressColor="@color/color_progress"circleview:progressMaximumValue="10"circleview:progressMinimumValue="0"circleview:progressStepValue="1"circleview:progressStepAsInteger="false"circleview:progressWidth="15dp"circleview:textColor="@color/sample_green"circleview:textEnabled="true"circleview:textFont="fonts/Roboto-Bold.ttf"circleview:textSize="36sp"/>

Attribute configuration list

AttributeTypeDefaultDefault
progressCurrentValuefloatThe starting value0
progressMaximumValuefloatThe maximum allowed value of the circle view100
progressMinimumValuefloatThe minimum allowed value of the circle view0
progressStepValuefloatThe step allows the developer to set a constraint for the values the user can choose. If different from 0, the step will be considered and whenever the user moves the progress to a non-integer value, it will round it to its Ceiling or Floor (whichever is closer)0
progressStepAsIntegerbooleanThe step allows the developer to constraint the value to an integer rather than a floatfalse
progressBarSquaredbooleanIf there is no indicator overlapping it, the progress bar can be set as squared or roundedfalse
progressWidthdimensionThe width of the progress bar
progressColorcolorThe color of the progress bar
suffixEnabledbooleanSpecifies whether a suffix can be added after the progress value. Used to indicate time or currencies, etcfalse
suffixValuestringThe string value for the suffix. E.g. "EUR"false
hasIndicatorbooleanThe indicator is a simple small circle that leads the progress barfalse
indicatorColorcolorThe indicator's color
indicatorRadiusintegerSpecifies the radius, if it exists, of the indicator
arcWidthdimensionThe width of the circle's arc20
arcColorcolorThe color of the circle's arc.
arcHasBorderbooleanDefines whether the circle's arc has a border. By default, if has exists, has 1.2x the width of the circle's arc
arcBorderColorcolorSpecifies the arc's border color if the arc's border existsfalse
hasTextbooleanSpecifies whether the arc's current progress will be displayed in the center of the circletrue
textSizedimensionSpecifies the text size72
textColorcolorSpecifies the text color
textFontstringSpecifies the custom font attributeTypeface.DEFAULT
clockwisebooleanSpecifies whether the CircleView takes a clockwise or a counter-clockwise orientationtrue
enabledbooleanSpecifies whether the user can interact (changing the progress) with the CircleView or not. Made with the intent of allowing the developer to lock the value and operate it without user interactiontrue

CircleView Change Listener

You can keep track of the values when they change as well as the moment when the point tracking starts or stops.

publicinterfaceCircleViewChangeListener{voidonPointsChanged(CircleViewcircleView, floatpoints); voidonStartTracking(CircleViewcircleView); voidonStopTracking(CircleViewcircleView)}

CircleView Animation (Wrapper)

In order to facilitate animations (because yeah, animations are the coolest part of views), the custom CircleViewAnimation wrapper has been added. Configurations are few and easy to implement. Notes :

  1. The AnimationListener is bound to the View. Thus said, if the Activity goes to the background, the animation will be briefly paused until it comes back to the foreground.
  2. To complement the previous point, the method setTimerOperationOnFinish allows you to specify a Runnable that will run at the end of the duration regardless of the Activity's state

Consider the following example :

CircleViewcircleView = (CircleView) findViewById(R.id.circle_view); CircleViewAnimationcircleViewAnimation = newCircleViewAnimation(circleView) .setAnimationStyle(AnimationStyle.CONTINUOUS) .setDuration(circleView.getProgressValue()) .setCustomAnimationListener(newAnimation.AnimationListener(){@OverridepublicvoidonAnimationStart(Animationanimation){// Animation Starts } @OverridepublicvoidonAnimationEnd(Animationanimation){// Animation Ends } @OverridepublicvoidonAnimationRepeat(Animationanimation){} }).setTimerOperationOnFinish(newRunnable(){@Overridepublicvoidrun(){// Run when the duration reaches 0. Regardless of the AnimationLifecycle or main thread.// Runs and triggers on background. } }) .setCustomInterpolator(newLinearInterpolator());

About

A 'Google Fit'-like circular view

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java100.0%