Skip to content

Commit 9c16f86

Browse files
committed
1.0.0 done.
1 parent 7beb6a3 commit 9c16f86

File tree

5 files changed

+81
-33
lines changed

5 files changed

+81
-33
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
tools:context=".MainActivity">
88

99
<com.sn.lib.NestedProgress
10+
android:id="@+id/emre"
1011
android:layout_width="wrap_content"
1112
android:layout_height="wrap_content"
12-
app:layout_constraintEnd_toEndOf="parent"
13+
app:innerAnimInterpolator="accelerateDecelerate"
1314
app:layout_constraintStart_toStartOf="parent"
14-
app:layout_constraintTop_toTopOf="parent" />
15+
app:layout_constraintTop_toTopOf="parent"
16+
app:outerAnimInterpolator="linear" />
1517

1618

1719
</androidx.constraintlayout.widget.ConstraintLayout>

lib/src/main/java/com/sn/lib/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ object Constants {
66
val COLOR_BLUE = Color.parseColor("#2666CF")
77
val COLOR_LIGHT_BLUE = Color.parseColor("#D3DEDC")
88

9+
const val SIZE_FACTOR = 1.0F
910
const val CIRCLE_RADIUS = 360
1011
const val INNER_LOADER_POS = 80
1112
const val OUTER_LOADER_POS = 60

lib/src/main/java/com/sn/lib/NestedProgress.kt

Lines changed: 75 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.util.AttributeSet
99
import android.view.View
1010
import android.view.animation.LinearInterpolator
1111
import android.view.animation.OvershootInterpolator
12+
import androidx.annotation.ColorInt
1213
import com.sn.lib.Constants.ANIM_DURATION
1314
import com.sn.lib.Constants.CIRCLE_RADIUS
1415
import com.sn.lib.Constants.COLOR_BLUE
@@ -21,41 +22,87 @@ import com.sn.lib.Constants.OUTER_ANIM_INTERPOLATOR
2122
import com.sn.lib.Constants.OUTER_LOADER_POS
2223
import com.sn.lib.Constants.OUTER_LOADER_LENGTH
2324
import com.sn.lib.Constants.OUTER_STROKE_WIDTH
25+
import com.sn.lib.Constants.SIZE_FACTOR
26+
import java.lang.IllegalArgumentException
2427
import kotlin.math.min
28+
import kotlin.math.roundToInt
29+
30+
/**
31+
* @author Aydin Emre E.
32+
* @version 1.0.1
33+
* @since 19-02-2022
34+
*/
2535

2636
class NestedProgress @JvmOverloads constructor(
2737
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
2838
) : View(context, attrs, defStyleAttr) {
2939

3040

31-
private var innerLoaderAnimDuration: Int = ANIM_DURATION
32-
private var outerLoaderAnimDuration: Int = ANIM_DURATION
33-
41+
// Animation value of progressions. These values are assigned to the "sweep angle" value in drawArc
3442
private var innerLoaderAnimValue: Int = 0
3543
private var outerLoaderAnimValue: Int = 0
3644

37-
private var innerAnimInterpolator = INNER_ANIM_INTERPOLATOR
38-
private var outerAnimInterpolator = OUTER_ANIM_INTERPOLATOR
39-
45+
// Animation always starts at 1 and goes full round until 360
4046
private val innerLoaderAnimator = ValueAnimator.ofInt(1, CIRCLE_RADIUS)
4147
private val outerLoaderAnimator = ValueAnimator.ofInt(1, CIRCLE_RADIUS)
4248

43-
private var innerLoaderLength: Float = INNER_LOADER_LENGTH
44-
private var outerLoaderLength: Float = OUTER_LOADER_LENGTH
45-
46-
private var innerLoaderStrokeWidth: Float = INNER_STROKE_WIDTH
47-
private var outerLoaderStrokeWidth: Float = OUTER_STROKE_WIDTH
48-
49-
private var innerLoaderColor: Int = COLOR_BLUE
50-
private var outerLoaderColor: Int = COLOR_LIGHT_BLUE
49+
private val innerLoadingRect: RectF = RectF()
50+
private val outerLoadingRect: RectF = RectF()
5151

5252
private val paint = Paint().apply {
5353
this.style = Paint.Style.STROKE
5454
this.isAntiAlias = true
5555
}
5656

57-
private val innerLoadingRect: RectF = RectF()
58-
private val outerLoadingRect: RectF = RectF()
57+
58+
@Suppress("UNUSED_VARIABLE")
59+
private var innerLoaderAnimDuration: Int = ANIM_DURATION
60+
61+
@Suppress("UNUSED_VARIABLE")
62+
private var outerLoaderAnimDuration: Int = ANIM_DURATION
63+
64+
@Suppress("UNUSED_VARIABLE")
65+
var innerAnimInterpolator = INNER_ANIM_INTERPOLATOR
66+
67+
@Suppress("UNUSED_VARIABLE")
68+
var outerAnimInterpolator = OUTER_ANIM_INTERPOLATOR
69+
70+
/** There is no limit value for stroke width, but correct values should be used for a smooth display * */
71+
@Suppress("UNUSED_VARIABLE")
72+
var innerLoaderStrokeWidth: Float = INNER_STROKE_WIDTH
73+
74+
@Suppress("UNUSED_VARIABLE")
75+
var outerLoaderStrokeWidth: Float = OUTER_STROKE_WIDTH
76+
77+
@ColorInt
78+
@Suppress("UNUSED_VARIABLE")
79+
var innerLoaderColor: Int = COLOR_BLUE
80+
81+
@ColorInt
82+
@Suppress("UNUSED_VARIABLE")
83+
var outerLoaderColor: Int = COLOR_LIGHT_BLUE
84+
85+
/** The maximum angle at which you can see a movement in the animation is 359
86+
* -innerLoaderLength
87+
* -outerLoaderLength
88+
* **/
89+
90+
@Suppress("UNUSED_VARIABLE")
91+
var innerLoaderLength: Float = INNER_LOADER_LENGTH
92+
93+
@Suppress("UNUSED_VARIABLE")
94+
var outerLoaderLength: Float = OUTER_LOADER_LENGTH
95+
96+
/** The library ignores the dp value so you should keep the sizeFactor value range 1 and 3.
97+
* In case you exceed value you will get IllegalArgumentException
98+
* @throws IllegalArgumentException
99+
* */
100+
@Suppress("UNUSED_VARIABLE")
101+
var sizeFactor: Float = SIZE_FACTOR
102+
set(value) {
103+
field =
104+
if (value > 3.0f && value < 1.0f) throw IllegalArgumentException("sizeFactor Must be range 1.0 and 3.0") else value
105+
}
59106

60107
init {
61108
val attributes = context.obtainStyledAttributes(attrs, R.styleable.NestedProgress)
@@ -112,6 +159,7 @@ class NestedProgress @JvmOverloads constructor(
112159
this.outerAnimInterpolator
113160
)
114161

162+
sizeFactor = attributes.getFloat(R.styleable.NestedProgress_sizeFactor, this.sizeFactor)
115163

116164
attributes.recycle()
117165

@@ -127,16 +175,17 @@ class NestedProgress @JvmOverloads constructor(
127175
val centerH: Float = height / 2f
128176

129177
innerLoadingRect.set(
130-
centerW - INNER_LOADER_POS,
131-
centerH - INNER_LOADER_POS,
132-
centerW + INNER_LOADER_POS,
133-
centerH + INNER_LOADER_POS
178+
centerW - (INNER_LOADER_POS * sizeFactor),
179+
centerH - (INNER_LOADER_POS * sizeFactor),
180+
centerW + (INNER_LOADER_POS * sizeFactor),
181+
centerH + (INNER_LOADER_POS * sizeFactor)
134182
)
183+
135184
outerLoadingRect.set(
136-
centerW - OUTER_LOADER_POS,
137-
centerH - OUTER_LOADER_POS,
138-
centerW + OUTER_LOADER_POS,
139-
centerH + OUTER_LOADER_POS
185+
centerW - (OUTER_LOADER_POS * sizeFactor),
186+
centerH - (OUTER_LOADER_POS * sizeFactor),
187+
centerW + (OUTER_LOADER_POS * sizeFactor),
188+
centerH + (OUTER_LOADER_POS * sizeFactor)
140189
)
141190

142191
updatePaint(outerLoaderColor, outerLoaderStrokeWidth)
@@ -161,8 +210,8 @@ class NestedProgress @JvmOverloads constructor(
161210

162211
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
163212
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
164-
val desiredWidth = 300
165-
val desiredHeight = 300
213+
val desiredWidth = (300 * sizeFactor).roundToInt()
214+
val desiredHeight = (300 * sizeFactor).roundToInt()
166215

167216
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
168217
val widthSize = MeasureSpec.getSize(widthMeasureSpec)

lib/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<attr name="innerLoaderColor" format="color" />
1010
<attr name="innerLoaderStrokeWidth" format="float" />
1111
<attr name="outerLoaderStrokeWidth" format="float" />
12+
<attr name="sizeFactor" format="float" />
1213
<attr name="innerAnimInterpolator" format="enum">
1314
<enum name="accelerate" value="0" />
1415
<enum name="decelerate" value="1" />

lib/src/main/res/values/colors.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)