Skip to content

Commit 94257ac

Browse files
authored
Merge pull request #13 from JDevZone/dev
netflix sample gif added
2 parents 869d274 + 87ee812 commit 94257ac

5 files changed

Lines changed: 101 additions & 17 deletions

File tree

art/netflix_anim.gif

233 KB
Loading

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.50'
4+
ext.kotlin_version = '1.3.72'
55
repositories {
66
google()
77
jcenter()
88

99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.5.2'
11+
classpath 'com.android.tools.build:gradle:3.6.3'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1414
// NOTE: Do not place your application dependencies here; they belong

fillprogresslayout/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ group='com.github.JDevZone'
77

88
android {
99
compileSdkVersion 29
10-
buildToolsVersion "29.0.2"
10+
buildToolsVersion "29.0.3"
1111

1212

1313
defaultConfig {
1414
minSdkVersion 17
1515
targetSdkVersion 29
1616
versionCode 1
1717
versionName "1.0"
18-
1918
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2019

2120
}
22-
21+
kotlinOptions {
22+
jvmTarget = '1.8'
23+
}
2324
buildTypes {
2425
release {
2526
minifyEnabled false
@@ -32,10 +33,10 @@ android {
3233
dependencies {
3334
implementation fileTree(dir: 'libs', include: ['*.jar'])
3435
implementation 'androidx.appcompat:appcompat:1.1.0'
35-
implementation "androidx.core:core-ktx:1.1.0"
36+
implementation "androidx.core:core-ktx:1.3.0"
3637
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3738

38-
testImplementation 'junit:junit:4.12'
39+
testImplementation 'junit:junit:4.13'
3940
androidTestImplementation 'androidx.test:runner:1.2.0'
4041
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
4142
}

fillprogresslayout/src/main/java/com/devzone/fillprogresslayout/FillProgressLayout.kt

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.devzone.fillprogresslayout
22

3+
import android.animation.TimeInterpolator
34
import android.animation.ValueAnimator
45
import android.content.Context
56
import android.content.res.TypedArray
@@ -24,6 +25,7 @@ class FillProgressLayout : LinearLayout {
2425
const val RIGHT_TO_LEFT = 1
2526
const val TOP_TO_BOTTOM = 2
2627
const val BOTTOM_TO_TOP = 3
28+
2729
//specific for gradient direction
2830
const val TOP_LEFT_TO_BOTTOM_RIGHT = 4
2931
const val TOP_RIGHT_TO_BOTTOM_LEFT = 5
@@ -42,6 +44,7 @@ class FillProgressLayout : LinearLayout {
4244
private val defIsRestart = false
4345
private val defIsRounded = false
4446
private val defGradientMovement = false
47+
private val defAnimInterpolator = AccelerateDecelerateInterpolator()
4548

4649
// customisable values
4750
private var isRounded = defIsRounded
@@ -56,6 +59,8 @@ class FillProgressLayout : LinearLayout {
5659
private var mGradientDirection = defDirection
5760
private var mGradientColors = intArrayOf()
5861

62+
private var animInterpolator: TimeInterpolator = defAnimInterpolator
63+
5964
private var oldProgress = 0
6065
private var currentProgress = 0
6166

@@ -136,7 +141,10 @@ class FillProgressLayout : LinearLayout {
136141
setGradientDirection(gradDirection)
137142

138143
val gradMovement =
139-
array.getBoolean(R.styleable.FillProgressLayout_fpl_gradientMovement, defGradientMovement)
144+
array.getBoolean(
145+
R.styleable.FillProgressLayout_fpl_gradientMovement,
146+
defGradientMovement
147+
)
140148
setGradientMovement(gradMovement)
141149

142150
try {
@@ -253,21 +261,29 @@ class FillProgressLayout : LinearLayout {
253261

254262
//---------------------public setters--------------------------------------------------------------------//
255263

256-
fun setProgress(inputProgress: Int,animated:Boolean=true) {
264+
/**
265+
* This method is used to set the current progress value externally
266+
* with or without animation
267+
* @param inputProgress current progress value
268+
* @param animated should animate filling
269+
*/
270+
fun setProgress(inputProgress: Int, animated: Boolean = true) {
257271
if (inputProgress in 0..maxProgress) {
258272
clearAnimation()
259-
if(animated) {
273+
if (animated) {
260274
val animator = ValueAnimator.ofInt(oldProgress, inputProgress)
261-
animator.interpolator = AccelerateDecelerateInterpolator()
275+
animator.interpolator = animInterpolator
262276
animator.addUpdateListener { anm ->
263277
currentProgress = anm.animatedValue as Int
264278
updateRect(rectF = progressRectF)
265279
ViewCompat.postInvalidateOnAnimation(this)
266280
}
267-
animator.doOnEnd { doOnProgressEnd?.invoke(this); if (!isRestart) oldProgress = inputProgress }
281+
animator.doOnEnd {
282+
doOnProgressEnd?.invoke(this); if (!isRestart) oldProgress = inputProgress
283+
}
268284
animator.setDuration(((kotlin.math.abs(inputProgress - oldProgress)) * mDurationFactor).toLong())
269285
.start()
270-
}else{
286+
} else {
271287
currentProgress = inputProgress
272288
updateRect(rectF = progressRectF)
273289
doOnProgressEnd?.invoke(this)
@@ -276,20 +292,46 @@ class FillProgressLayout : LinearLayout {
276292
}
277293
}
278294

295+
/**
296+
* This method is used to set progress animation interpolator
297+
* for different filling effects
298+
* @see TimeInterpolator
299+
* @param interpolator interpolator for animation
300+
* default value is
301+
* @see AccelerateDecelerateInterpolator
302+
*/
303+
fun setAnimationInterpolator(interpolator: TimeInterpolator) {
304+
animInterpolator = interpolator
305+
}
306+
307+
/**
308+
* This method is used to set the background color
309+
* @param resId color resource id
310+
*/
279311
fun setProgressBackgroundColor(@ColorRes resId: Int) {
280312
if (isValidRes(resId)) {
281313
mBackgroundColor = ContextCompat.getColor(context, resId)
282314
initPaint()
283315
}
284316
}
285317

318+
/**
319+
* This method is used to set the foreground/progress color
320+
* @param resId color resource id
321+
*/
286322
fun setProgressColor(@ColorRes resId: Int) {
287323
if (isValidRes(resId)) {
288324
mProgressColor = ContextCompat.getColor(context, resId)
289325
initPaint()
290326
}
291327
}
292328

329+
/**
330+
* This method is used to set multiple colors for gradient effect
331+
* @param resIds array of color resource ids
332+
* @param extractResColor flag for color extraction
333+
* @see ContextCompat.getColor
334+
*/
293335
fun setProgressColors(@ColorRes resIds: IntArray, extractResColor: Boolean = true) {
294336
try {
295337
val filtered = resIds.filter { isValidRes(it) }
@@ -304,41 +346,82 @@ class FillProgressLayout : LinearLayout {
304346
}
305347
}
306348

307-
349+
/**
350+
* This method is used to make progress layout corners rounded
351+
* and roundness is adjusted with a float value
352+
* @param radius corner radius for progress layout
353+
*/
308354
fun setCornerRadius(radius: Float) {
309355
if (radius in 0f..maxProgress.toFloat()) {
310356
setRoundedCorners(true)
311357
this.mCornerRadius = radius
312358
}
313359
}
314360

315-
361+
/**
362+
* This method is used to make progress layout corners rounded
363+
* @param isRounded flag for rounded corners support
364+
*/
316365
fun setRoundedCorners(isRounded: Boolean) {
317366
this.isRounded = isRounded
318367
}
319368

369+
/**
370+
* This method is used to adjust the movement of progress gradient
371+
* if true the gradient will move will progress and
372+
* if false the gradient will stay as background paint and will reveals with progress
373+
* @param gradMovement flag for gradient movement
374+
*/
320375
fun setGradientMovement(gradMovement: Boolean) {
321376
this.gradientMovement = gradMovement
322377
}
323378

379+
/**
380+
* @param duration should be in millis i.e 2000 for 2 seconds
381+
*/
324382
fun setDuration(duration: Long) {
325383
if (duration.toInt() == 0 || duration < 0) return
326384
mDurationFactor = (duration / 100).toInt()
327385
}
328386

387+
/**
388+
* This method is used to make progress restart or resume from old position
389+
* if true the gradient will restart from zero to progress value
390+
* if false the gradient will resume from old to new progress value
391+
* @param isRestart flag for gradient movement
392+
*/
329393
fun shouldStartFromZero(isRestart: Boolean) {
330394
this.isRestart = isRestart
331395
}
332396

397+
/**
398+
* This method is used to set the direction of fill
399+
* from values LEFT_TO_RIGHT to BOTTOM_TO_TOP
400+
* default value is #LEFT_TO_RIGHT
401+
* @param direction value for fill direction
402+
* @see LEFT_TO_RIGHT
403+
*/
333404
fun setFillDirection(direction: Int) {
334405
mDirection = if (direction in LEFT_TO_RIGHT..BOTTOM_TO_TOP) direction else defDirection
335406
}
336407

408+
/**
409+
* This method is used to set the direction of gradient fill
410+
* from values LEFT_TO_RIGHT to BOTTOM_LEFT_TO_TOP_RIGHT
411+
* default value is #LEFT_TO_RIGHT
412+
* @param direction value for fill direction
413+
* @see LEFT_TO_RIGHT
414+
*/
337415
fun setGradientDirection(direction: Int) {
338416
mGradientDirection =
339417
if (direction in LEFT_TO_RIGHT..BOTTOM_LEFT_TO_TOP_RIGHT) direction else defDirection
340418
}
341419

420+
/**
421+
* This method is used to set a listener to get callback
422+
* when progress animation ends
423+
* @param listener a lambda function to invoke after progress animation ends
424+
*/
342425
fun setDoOnProgressEnd(listener: ((v: View) -> Unit)) {
343426
doOnProgressEnd = listener
344427
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 02 12:16:53 IST 2019
1+
#Sun Jun 07 09:06:20 IST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 commit comments

Comments
 (0)