From 5c064fc67d122c7e4f04e7d0e50fb2c42d264ddc Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Thu, 20 Sep 2018 19:01:04 +0530 Subject: [PATCH 1/7] added fidget view --- .../com/agrawalsuneet/loaders/MainActivity.kt | 2 +- app/src/main/res/layout/main_fidget.xml | 54 ++++++++ .../loaderspack/basicviews/FidgetView.kt | 119 ++++++++++++++++++ 3 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/layout/main_fidget.xml create mode 100644 loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt diff --git a/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt b/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt index eadb8e4..36d8302 100644 --- a/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt +++ b/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt @@ -13,7 +13,7 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.main_arcprogress) + setContentView(R.layout.main_fidget) supportActionBar?.setTitle("ArcProgressLoader") diff --git a/app/src/main/res/layout/main_fidget.xml b/app/src/main/res/layout/main_fidget.xml new file mode 100644 index 0000000..d7713cc --- /dev/null +++ b/app/src/main/res/layout/main_fidget.xml @@ -0,0 +1,54 @@ + + + + + + + + + + \ No newline at end of file diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt new file mode 100644 index 0000000..1e346c8 --- /dev/null +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt @@ -0,0 +1,119 @@ +package com.agrawalsuneet.loaderspack.basicviews + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Paint +import android.util.AttributeSet +import android.view.View +import com.agrawalsuneet.loaderspack.R + +/** + * Created by agrawalsuneet on 9/20/18. + */ + +class FidgetView : View { + + var fidgetRadius: Int = 130 + var sidesRadius: Int = 130 + var bodyColor: Int = resources.getColor(R.color.red) + var sideCirclesColor = resources.getColor(R.color.grey) + + private val centerPaint: Paint = Paint() + private val sidesPaint: Paint = Paint() + + private var calWidth = 0.0f + private var calHeight = 0.0f + private val sin30 = 0.5 + private val cos30 = 0.866 + + private val distanceFactor = 0.8 + + constructor(context: Context) : super(context) { + initValues() + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + initAttributes(attrs) + initValues() + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + initAttributes(attrs) + initValues() + } + + + fun initAttributes(attrs: AttributeSet) { + + /*val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcView, 0, 0) + + this.arcRadius = typedArray.getDimensionPixelSize(R.styleable.ArcView_arcRadius, 60) + this.arcWidth = typedArray.getDimensionPixelSize(R.styleable.ArcView_arcWidth, 10) + + this.startAngle = typedArray.getFloat(R.styleable.ArcView_startAngle, 0.0f) + this.sweepAngle = typedArray.getFloat(R.styleable.ArcView_sweepAngle, 180.0f) + + this.arcColor = typedArray.getColor(R.styleable.ArcView_arcColor, resources.getColor(R.color.red)) + + this.drawOnlyStroke = typedArray.getBoolean(R.styleable.ArcView_drawOnlyStroke, true) + + typedArray.recycle()*/ + } + + private fun initValues() { + + centerPaint.isAntiAlias = true + centerPaint.style = Paint.Style.FILL + centerPaint.color = bodyColor + + sidesPaint.isAntiAlias = true + sidesPaint.style = Paint.Style.FILL + sidesPaint.color = sideCirclesColor + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + + calWidth = (2 * sidesRadius) + (2 * cos30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() + + calHeight = ((2 * sidesRadius) + + (distanceFactor * (fidgetRadius + sidesRadius)) + + (sin30 * distanceFactor * (fidgetRadius + sidesRadius))).toFloat() + setMeasuredDimension(calWidth.toInt(), calHeight.toInt()) + } + + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + + val centerX = (calWidth / 2) + val centerY = (sidesRadius + (distanceFactor * (fidgetRadius + sidesRadius))).toFloat() + + //center circle + canvas.drawCircle(centerX, centerY, fidgetRadius.toFloat(), centerPaint) + + //top circle + var xCor = calWidth / 2 + var yCor = (centerY - ((fidgetRadius + sidesRadius) * distanceFactor)).toFloat() + canvas.drawCircle(xCor, yCor, sidesRadius.toFloat(), centerPaint) + + canvas.drawCircle(xCor, yCor, (sidesRadius * 3 / 5).toFloat(), sidesPaint) + + //right circle + xCor = centerX + (cos30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() + yCor = centerY + (sin30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() + canvas.drawCircle(xCor, yCor, sidesRadius.toFloat(), centerPaint) + + canvas.drawCircle(xCor, yCor, (sidesRadius * 3 / 5).toFloat(), sidesPaint) + + //left circle + xCor = centerX - (cos30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() + yCor = centerY + (sin30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() + canvas.drawCircle(xCor, yCor, sidesRadius.toFloat(), centerPaint) + + canvas.drawCircle(xCor, yCor, (sidesRadius * 3 / 5).toFloat(), sidesPaint) + + pivotX = centerX + pivotY = centerY + } +} \ No newline at end of file From 6f3bb85ac32a17bc3befbf926ac95c248a4d8de7 Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Sat, 22 Sep 2018 17:42:52 +0530 Subject: [PATCH 2/7] implemented loader --- .../loaders/MainActivityJava.java | 9 +- app/src/main/res/layout/main_fidget.xml | 2 +- .../loaderspack/basicviews/FidgetView.kt | 9 ++ .../loaderspack/loaders/FidgetLoader.kt | 126 ++++++++++++++++++ 4 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt diff --git a/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java b/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java index 12824ae..4bc0067 100644 --- a/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java +++ b/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java @@ -13,6 +13,7 @@ import com.agrawalsuneet.loaderspack.loaders.CurvesLoader; import com.agrawalsuneet.loaderspack.loaders.MultipleRippleLoader; import com.agrawalsuneet.loaderspack.loaders.RingAndCircleLoader; +import com.agrawalsuneet.loaderspack.loaders.RotatingCircularSticksLoader; /** * Created by suneet on 10/31/17. @@ -48,17 +49,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { container.addView(clockLoader); //RotatingCircularSticksLoader - /*RotatingCircularSticksLoader loader = new RotatingCircularSticksLoader(this, + RotatingCircularSticksLoader loader = new RotatingCircularSticksLoader(this, 16, 100f, 50f, ContextCompat.getColor(this, R.color.blue), ContextCompat.getColor(this, android.R.color.white)); loader.setAnimDuration(5000); - container.addView(loader);*/ + container.addView(loader); //CircularSticksLoader - CircularSticksLoader loader = new CircularSticksLoader(this, 16, + /*CircularSticksLoader loader = new CircularSticksLoader(this, 16, 200f, 100f, ContextCompat.getColor(this, R.color.blue), ContextCompat.getColor(this, R.color.red), @@ -69,7 +70,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { loader.setSecondShadowColor(ContextCompat.getColor(this, R.color.yellow)); loader.setAnimDuration(100); - container.addView(loader); + container.addView(loader);*/ //MultipleRippleLoader diff --git a/app/src/main/res/layout/main_fidget.xml b/app/src/main/res/layout/main_fidget.xml index d7713cc..9d27a0c 100644 --- a/app/src/main/res/layout/main_fidget.xml +++ b/app/src/main/res/layout/main_fidget.xml @@ -46,7 +46,7 @@ --> - diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt index 1e346c8..7395ddc 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt @@ -28,6 +28,7 @@ class FidgetView : View { private val distanceFactor = 0.8 + constructor(context: Context) : super(context) { initValues() } @@ -42,6 +43,14 @@ class FidgetView : View { initValues() } + constructor(context: Context, fidgetRadius: Int, sidesRadius: Int, bodyColor: Int, sideCirclesColor: Int) : super(context) { + this.fidgetRadius = fidgetRadius + this.sidesRadius = sidesRadius + this.bodyColor = bodyColor + this.sideCirclesColor = sideCirclesColor + initValues() + } + fun initAttributes(attrs: AttributeSet) { diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt new file mode 100644 index 0000000..ef1a053 --- /dev/null +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt @@ -0,0 +1,126 @@ +package com.agrawalsuneet.loaderspack.loaders + +import android.content.Context +import android.util.AttributeSet +import android.view.Gravity +import android.view.ViewTreeObserver +import android.view.animation.Animation +import android.view.animation.LinearInterpolator +import android.view.animation.RotateAnimation +import android.widget.LinearLayout +import com.agrawalsuneet.loaderspack.R +import com.agrawalsuneet.loaderspack.basicviews.FidgetView +import com.agrawalsuneet.loaderspack.basicviews.LoaderContract + +/** + * Created by agrawalsuneet on 9/20/18. + */ +class FidgetLoader : LinearLayout, LoaderContract { + + + var fidgetRadius: Int = 130 + var bodyColor: Int = resources.getColor(R.color.red) + var sideCirclesColor = resources.getColor(R.color.grey) + + var animDuration: Int = 50000 + + private val sin30 = 0.5 + private val cos30 = 0.866 + + private val distanceFactor = 0.8 + + private lateinit var fidgetView: FidgetView + + constructor(context: Context) : super(context) { + initView() + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + initAttributes(attrs) + initView() + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + initAttributes(attrs) + initView() + } + + + override fun initAttributes(attrs: AttributeSet) { + /*val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CurvesLoader, 0, 0) + + this.noOfCurves = typedArray.getInteger(R.styleable.CurvesLoader_curves_noOfCurves, 4) + + this.outermostCurveRadius = typedArray.getDimensionPixelSize(R.styleable.CurvesLoader_curves_outermostCurveRadius, 100) + + this.curveWidth = typedArray.getDimensionPixelSize(R.styleable.CurvesLoader_curves_curveWidth, 10) + this.distanceBetweenCurves = typedArray.getDimensionPixelSize(R.styleable.CurvesLoader_curves_distanceBetweenCurves, 10) + + this.curveSweepAngle = typedArray.getFloat(R.styleable.CurvesLoader_curves_curveSweepAngle, 160.0f) + + this.curveColor = typedArray.getColor(R.styleable.CurvesLoader_curves_curveColor, + resources.getColor(android.R.color.holo_red_light)) + + this.animDuration = typedArray.getInt(R.styleable.CurvesLoader_curves_animDuration, 1500) + + this.interpolator = AnimationUtils.loadInterpolator(context, + typedArray.getResourceId(R.styleable.CurvesLoader_curves_interpolator, + android.R.anim.linear_interpolator)) + + typedArray.recycle()*/ + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + + val widthHeight = (1.2 * fidgetRadius) + (4 * fidgetRadius).toFloat() + setMeasuredDimension(widthHeight.toInt(), widthHeight.toInt()) + } + + private fun initView() { + removeAllViews() + removeAllViewsInLayout() + + this.gravity = Gravity.CENTER_HORIZONTAL + this.orientation = LinearLayout.VERTICAL + + fidgetView = FidgetView(context, fidgetRadius, fidgetRadius, bodyColor, sideCirclesColor) + this.addView(fidgetView) + + val loaderView = this + + + viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + startLoading() + + val vto = loaderView.viewTreeObserver + vto.removeOnGlobalLayoutListener(this) + } + }) + } + + private fun startLoading() { + val anim = getRotateAnim() + fidgetView.startAnimation(anim) + } + + private fun getRotateAnim(): RotateAnimation { + + val fromDegree = 0.0f + val toDegree = 360f * 5.0f + + val centerX = (fidgetRadius) + (cos30 * distanceFactor * (fidgetRadius + fidgetRadius)).toFloat() + val centerY = (fidgetRadius + (distanceFactor * (fidgetRadius + fidgetRadius))).toFloat() + + val rotateAnimation = RotateAnimation(fromDegree, toDegree, + centerX, centerY) + rotateAnimation.duration = animDuration.toLong() + rotateAnimation.fillAfter = true + rotateAnimation.interpolator = LinearInterpolator() + rotateAnimation.repeatCount = Animation.INFINITE + + return rotateAnimation + } + +} \ No newline at end of file From 8db3775366f9efe4d301cfae6ef2dd3f999f54a9 Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Sat, 22 Sep 2018 21:02:36 +0530 Subject: [PATCH 3/7] finalized fidget view --- .../loaders/MainActivityJava.java | 8 +- app/src/main/res/layout/main_fidget.xml | 12 ++- .../loaderspack/basicviews/FidgetView.kt | 74 ++++++++----------- .../loaderspack/loaders/FidgetLoader.kt | 33 +++------ loaderspack/src/main/res/values/attrs.xml | 6 ++ 5 files changed, 64 insertions(+), 69 deletions(-) diff --git a/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java b/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java index 4bc0067..f94a32f 100644 --- a/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java +++ b/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java @@ -30,7 +30,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_main_clock); - //Clock Loader + /*//Clock Loader ClockLoader clockLoader = new ClockLoader(this); clockLoader.setOuterCircleBorderWidth(8.0f); clockLoader.setBigCircleRadius(150.0f); @@ -59,7 +59,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { //CircularSticksLoader - /*CircularSticksLoader loader = new CircularSticksLoader(this, 16, + *//*CircularSticksLoader loader = new CircularSticksLoader(this, 16, 200f, 100f, ContextCompat.getColor(this, R.color.blue), ContextCompat.getColor(this, R.color.red), @@ -70,7 +70,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { loader.setSecondShadowColor(ContextCompat.getColor(this, R.color.yellow)); loader.setAnimDuration(100); - container.addView(loader);*/ + container.addView(loader);*//* //MultipleRippleLoader @@ -121,7 +121,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { 10.0f, 180.0f, getResources().getIntArray(R.array.colors_rgb)); - container.addView(arcProgressLoader); + container.addView(arcProgressLoader);*/ } diff --git a/app/src/main/res/layout/main_fidget.xml b/app/src/main/res/layout/main_fidget.xml index 9d27a0c..b6e11f0 100644 --- a/app/src/main/res/layout/main_fidget.xml +++ b/app/src/main/res/layout/main_fidget.xml @@ -1,5 +1,6 @@ --> + + + android:layout_height="wrap_content" + android:layout_margin="16dp" /> \ No newline at end of file diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt index 7395ddc..85939a3 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt @@ -13,22 +13,22 @@ import com.agrawalsuneet.loaderspack.R class FidgetView : View { - var fidgetRadius: Int = 130 - var sidesRadius: Int = 130 + companion object { + const val distanceFactor = 0.8 + } + + var fidgetRadius: Int = 100 var bodyColor: Int = resources.getColor(R.color.red) var sideCirclesColor = resources.getColor(R.color.grey) private val centerPaint: Paint = Paint() private val sidesPaint: Paint = Paint() - private var calWidth = 0.0f - private var calHeight = 0.0f + private var calWidthHeight = 0.0f + private val sin30 = 0.5 private val cos30 = 0.866 - private val distanceFactor = 0.8 - - constructor(context: Context) : super(context) { initValues() } @@ -43,9 +43,8 @@ class FidgetView : View { initValues() } - constructor(context: Context, fidgetRadius: Int, sidesRadius: Int, bodyColor: Int, sideCirclesColor: Int) : super(context) { + constructor(context: Context, fidgetRadius: Int, bodyColor: Int, sideCirclesColor: Int) : super(context) { this.fidgetRadius = fidgetRadius - this.sidesRadius = sidesRadius this.bodyColor = bodyColor this.sideCirclesColor = sideCirclesColor initValues() @@ -54,19 +53,13 @@ class FidgetView : View { fun initAttributes(attrs: AttributeSet) { - /*val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcView, 0, 0) + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FidgetView, 0, 0) - this.arcRadius = typedArray.getDimensionPixelSize(R.styleable.ArcView_arcRadius, 60) - this.arcWidth = typedArray.getDimensionPixelSize(R.styleable.ArcView_arcWidth, 10) + fidgetRadius = typedArray.getDimensionPixelSize(R.styleable.FidgetView_fidgetRadius, 100) + bodyColor = typedArray.getColor(R.styleable.FidgetView_fidgetBodyColor, resources.getColor(R.color.red)) + sideCirclesColor = typedArray.getColor(R.styleable.FidgetView_fidgetSideCirclesColor, resources.getColor(R.color.grey)) - this.startAngle = typedArray.getFloat(R.styleable.ArcView_startAngle, 0.0f) - this.sweepAngle = typedArray.getFloat(R.styleable.ArcView_sweepAngle, 180.0f) - - this.arcColor = typedArray.getColor(R.styleable.ArcView_arcColor, resources.getColor(R.color.red)) - - this.drawOnlyStroke = typedArray.getBoolean(R.styleable.ArcView_drawOnlyStroke, true) - - typedArray.recycle()*/ + typedArray.recycle() } private fun initValues() { @@ -83,46 +76,41 @@ class FidgetView : View { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, heightMeasureSpec) - calWidth = (2 * sidesRadius) + (2 * cos30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() - - calHeight = ((2 * sidesRadius) - + (distanceFactor * (fidgetRadius + sidesRadius)) - + (sin30 * distanceFactor * (fidgetRadius + sidesRadius))).toFloat() - setMeasuredDimension(calWidth.toInt(), calHeight.toInt()) + calWidthHeight = (2 * fidgetRadius) + (4 * distanceFactor * (fidgetRadius)).toFloat() + setMeasuredDimension(calWidthHeight.toInt(), calWidthHeight.toInt()) } override fun onDraw(canvas: Canvas) { super.onDraw(canvas) - val centerX = (calWidth / 2) - val centerY = (sidesRadius + (distanceFactor * (fidgetRadius + sidesRadius))).toFloat() + val centerXY = (calWidthHeight / 2) //center circle - canvas.drawCircle(centerX, centerY, fidgetRadius.toFloat(), centerPaint) + canvas.drawCircle(centerXY, centerXY, fidgetRadius.toFloat(), centerPaint) //top circle - var xCor = calWidth / 2 - var yCor = (centerY - ((fidgetRadius + sidesRadius) * distanceFactor)).toFloat() - canvas.drawCircle(xCor, yCor, sidesRadius.toFloat(), centerPaint) + var xCor = calWidthHeight / 2 + var yCor = (centerXY - ((2 * fidgetRadius) * distanceFactor)).toFloat() - canvas.drawCircle(xCor, yCor, (sidesRadius * 3 / 5).toFloat(), sidesPaint) + canvas.drawCircle(xCor, yCor, fidgetRadius.toFloat(), centerPaint) + canvas.drawCircle(xCor, yCor, (fidgetRadius * 3 / 5).toFloat(), sidesPaint) //right circle - xCor = centerX + (cos30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() - yCor = centerY + (sin30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() - canvas.drawCircle(xCor, yCor, sidesRadius.toFloat(), centerPaint) + xCor = centerXY + (cos30 * distanceFactor * (2 * fidgetRadius)).toFloat() + yCor = centerXY + (sin30 * distanceFactor * (2 * fidgetRadius)).toFloat() - canvas.drawCircle(xCor, yCor, (sidesRadius * 3 / 5).toFloat(), sidesPaint) + canvas.drawCircle(xCor, yCor, fidgetRadius.toFloat(), centerPaint) + canvas.drawCircle(xCor, yCor, (fidgetRadius * 3 / 5).toFloat(), sidesPaint) //left circle - xCor = centerX - (cos30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() - yCor = centerY + (sin30 * distanceFactor * (fidgetRadius + sidesRadius)).toFloat() - canvas.drawCircle(xCor, yCor, sidesRadius.toFloat(), centerPaint) + xCor = centerXY - (cos30 * distanceFactor * (2 * fidgetRadius)).toFloat() + yCor = centerXY + (sin30 * distanceFactor * (2 * fidgetRadius)).toFloat() - canvas.drawCircle(xCor, yCor, (sidesRadius * 3 / 5).toFloat(), sidesPaint) + canvas.drawCircle(xCor, yCor, fidgetRadius.toFloat(), centerPaint) + canvas.drawCircle(xCor, yCor, (fidgetRadius * 3 / 5).toFloat(), sidesPaint) - pivotX = centerX - pivotY = centerY + pivotX = centerXY + pivotY = centerXY } } \ No newline at end of file diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt index ef1a053..a43bc53 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt @@ -4,9 +4,7 @@ import android.content.Context import android.util.AttributeSet import android.view.Gravity import android.view.ViewTreeObserver -import android.view.animation.Animation -import android.view.animation.LinearInterpolator -import android.view.animation.RotateAnimation +import android.view.animation.* import android.widget.LinearLayout import com.agrawalsuneet.loaderspack.R import com.agrawalsuneet.loaderspack.basicviews.FidgetView @@ -18,16 +16,12 @@ import com.agrawalsuneet.loaderspack.basicviews.LoaderContract class FidgetLoader : LinearLayout, LoaderContract { - var fidgetRadius: Int = 130 + var fidgetRadius: Int = 100 var bodyColor: Int = resources.getColor(R.color.red) var sideCirclesColor = resources.getColor(R.color.grey) - var animDuration: Int = 50000 - - private val sin30 = 0.5 - private val cos30 = 0.866 - - private val distanceFactor = 0.8 + var animDuration: Int = 5000 + var interpolator: Interpolator = AccelerateDecelerateInterpolator() private lateinit var fidgetView: FidgetView @@ -49,7 +43,7 @@ class FidgetLoader : LinearLayout, LoaderContract { override fun initAttributes(attrs: AttributeSet) { /*val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CurvesLoader, 0, 0) - this.noOfCurves = typedArray.getInteger(R.styleable.CurvesLoader_curves_noOfCurves, 4) + fidgetRadius = typedArray.getInteger(R.styleable.CurvesLoader_curves_noOfCurves, 4) this.outermostCurveRadius = typedArray.getDimensionPixelSize(R.styleable.CurvesLoader_curves_outermostCurveRadius, 100) @@ -73,18 +67,18 @@ class FidgetLoader : LinearLayout, LoaderContract { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, heightMeasureSpec) - val widthHeight = (1.2 * fidgetRadius) + (4 * fidgetRadius).toFloat() - setMeasuredDimension(widthHeight.toInt(), widthHeight.toInt()) + val calWidthHeight = (2 * fidgetRadius) + (4 * FidgetView.distanceFactor * (fidgetRadius)).toFloat() + setMeasuredDimension(calWidthHeight.toInt(), calWidthHeight.toInt()) } private fun initView() { removeAllViews() removeAllViewsInLayout() - this.gravity = Gravity.CENTER_HORIZONTAL + this.gravity = Gravity.CENTER this.orientation = LinearLayout.VERTICAL - fidgetView = FidgetView(context, fidgetRadius, fidgetRadius, bodyColor, sideCirclesColor) + fidgetView = FidgetView(context, fidgetRadius, bodyColor, sideCirclesColor) this.addView(fidgetView) val loaderView = this @@ -108,16 +102,13 @@ class FidgetLoader : LinearLayout, LoaderContract { private fun getRotateAnim(): RotateAnimation { val fromDegree = 0.0f - val toDegree = 360f * 5.0f - - val centerX = (fidgetRadius) + (cos30 * distanceFactor * (fidgetRadius + fidgetRadius)).toFloat() - val centerY = (fidgetRadius + (distanceFactor * (fidgetRadius + fidgetRadius))).toFloat() + val toDegree = 360f * 20.0f val rotateAnimation = RotateAnimation(fromDegree, toDegree, - centerX, centerY) + fidgetView.pivotX, fidgetView.pivotY) rotateAnimation.duration = animDuration.toLong() rotateAnimation.fillAfter = true - rotateAnimation.interpolator = LinearInterpolator() + rotateAnimation.interpolator = interpolator rotateAnimation.repeatCount = Animation.INFINITE return rotateAnimation diff --git a/loaderspack/src/main/res/values/attrs.xml b/loaderspack/src/main/res/values/attrs.xml index 9f33333..8509695 100644 --- a/loaderspack/src/main/res/values/attrs.xml +++ b/loaderspack/src/main/res/values/attrs.xml @@ -17,6 +17,12 @@ + + + + + + From 4f9d1ae0d4b5eeb356437a7c1583b30a80892bee Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Sat, 22 Sep 2018 21:25:45 +0530 Subject: [PATCH 4/7] finished loader --- .../loaderspack/basicviews/FidgetView.kt | 8 ++-- .../loaderspack/loaders/FidgetLoader.kt | 41 +++++++++++-------- loaderspack/src/main/res/values/attrs.xml | 10 +++++ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt index 85939a3..e70c06e 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/FidgetView.kt @@ -18,8 +18,8 @@ class FidgetView : View { } var fidgetRadius: Int = 100 - var bodyColor: Int = resources.getColor(R.color.red) - var sideCirclesColor = resources.getColor(R.color.grey) + var bodyColor: Int = resources.getColor(android.R.color.holo_red_light) + var sideCirclesColor = resources.getColor(android.R.color.darker_gray) private val centerPaint: Paint = Paint() private val sidesPaint: Paint = Paint() @@ -56,8 +56,8 @@ class FidgetView : View { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FidgetView, 0, 0) fidgetRadius = typedArray.getDimensionPixelSize(R.styleable.FidgetView_fidgetRadius, 100) - bodyColor = typedArray.getColor(R.styleable.FidgetView_fidgetBodyColor, resources.getColor(R.color.red)) - sideCirclesColor = typedArray.getColor(R.styleable.FidgetView_fidgetSideCirclesColor, resources.getColor(R.color.grey)) + bodyColor = typedArray.getColor(R.styleable.FidgetView_fidgetBodyColor, resources.getColor(android.R.color.holo_red_light)) + sideCirclesColor = typedArray.getColor(R.styleable.FidgetView_fidgetSideCirclesColor, resources.getColor(android.R.color.darker_gray)) typedArray.recycle() } diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt index a43bc53..ee98f0c 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt @@ -15,12 +15,12 @@ import com.agrawalsuneet.loaderspack.basicviews.LoaderContract */ class FidgetLoader : LinearLayout, LoaderContract { - var fidgetRadius: Int = 100 - var bodyColor: Int = resources.getColor(R.color.red) - var sideCirclesColor = resources.getColor(R.color.grey) + var bodyColor: Int = resources.getColor(android.R.color.holo_red_light) + var sideCirclesColor = resources.getColor(android.R.color.darker_gray) - var animDuration: Int = 5000 + var noOfRotation: Int = 20 + var animDuration: Int = 3000 var interpolator: Interpolator = AccelerateDecelerateInterpolator() private lateinit var fidgetView: FidgetView @@ -39,29 +39,35 @@ class FidgetLoader : LinearLayout, LoaderContract { initView() } + constructor(context: Context?, fidgetRadius: Int, bodyColor: Int, sideCirclesColor: Int) : super(context) { + this.fidgetRadius = fidgetRadius + this.bodyColor = bodyColor + this.sideCirclesColor = sideCirclesColor + initView() + } + override fun initAttributes(attrs: AttributeSet) { - /*val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CurvesLoader, 0, 0) + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FidgetLoader, 0, 0) - fidgetRadius = typedArray.getInteger(R.styleable.CurvesLoader_curves_noOfCurves, 4) + fidgetRadius = typedArray.getInteger(R.styleable.FidgetLoader_fidget_fidgetRadius, 100) - this.outermostCurveRadius = typedArray.getDimensionPixelSize(R.styleable.CurvesLoader_curves_outermostCurveRadius, 100) + bodyColor = typedArray.getColor(R.styleable.FidgetLoader_fidget_bodyColor, + resources.getColor(android.R.color.holo_red_light)) - this.curveWidth = typedArray.getDimensionPixelSize(R.styleable.CurvesLoader_curves_curveWidth, 10) - this.distanceBetweenCurves = typedArray.getDimensionPixelSize(R.styleable.CurvesLoader_curves_distanceBetweenCurves, 10) + sideCirclesColor = typedArray.getColor(R.styleable.FidgetLoader_fidget_sideCirclesColor, + resources.getColor(android.R.color.darker_gray)) - this.curveSweepAngle = typedArray.getFloat(R.styleable.CurvesLoader_curves_curveSweepAngle, 160.0f) - this.curveColor = typedArray.getColor(R.styleable.CurvesLoader_curves_curveColor, - resources.getColor(android.R.color.holo_red_light)) + noOfRotation = typedArray.getInt(R.styleable.FidgetLoader_fidget_noOfRotation, 20) - this.animDuration = typedArray.getInt(R.styleable.CurvesLoader_curves_animDuration, 1500) + animDuration = typedArray.getInt(R.styleable.FidgetLoader_fidget_animDuration, 3000) this.interpolator = AnimationUtils.loadInterpolator(context, - typedArray.getResourceId(R.styleable.CurvesLoader_curves_interpolator, - android.R.anim.linear_interpolator)) + typedArray.getResourceId(R.styleable.FidgetLoader_fidget_interpolator, + android.R.anim.accelerate_decelerate_interpolator)) - typedArray.recycle()*/ + typedArray.recycle() } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { @@ -83,7 +89,6 @@ class FidgetLoader : LinearLayout, LoaderContract { val loaderView = this - viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { startLoading() @@ -102,7 +107,7 @@ class FidgetLoader : LinearLayout, LoaderContract { private fun getRotateAnim(): RotateAnimation { val fromDegree = 0.0f - val toDegree = 360f * 20.0f + val toDegree = 360f * noOfRotation val rotateAnimation = RotateAnimation(fromDegree, toDegree, fidgetView.pivotX, fidgetView.pivotY) diff --git a/loaderspack/src/main/res/values/attrs.xml b/loaderspack/src/main/res/values/attrs.xml index 8509695..d5d4fde 100644 --- a/loaderspack/src/main/res/values/attrs.xml +++ b/loaderspack/src/main/res/values/attrs.xml @@ -128,4 +128,14 @@ + + + + + + + + + + \ No newline at end of file From e77172588c47075fda4f56b014bb9fe1c583adf2 Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Sat, 22 Sep 2018 21:57:47 +0530 Subject: [PATCH 5/7] final layout and removed colors file --- .../res/layout/activity_main_circular.xml | 4 +- .../activity_main_circular_rotating.xml | 2 +- .../main/res/layout/activity_main_clock.xml | 10 +-- .../layout/activity_main_multipleripple.xml | 2 +- app/src/main/res/layout/main_curves.xml | 2 +- app/src/main/res/layout/main_fidget.xml | 72 +++++++++++-------- app/src/main/res/values/colors.xml | 5 +- .../loaderspack/basicviews/ArcView.kt | 4 +- .../basicviews/CircularSticksBaseView.kt | 4 +- .../loaderspack/loaders/ArcProgressLoader.kt | 6 +- .../loaders/CircularSticksLoader.kt | 8 +-- .../loaderspack/loaders/ClockLoader.kt | 20 +++--- .../loaderspack/loaders/FidgetLoader.kt | 6 +- .../loaders/MultipleRippleLoader.kt | 2 +- .../loaderspack/loaders/RippleLoader.kt | 4 +- .../loaders/RotatingCircularSticksLoader.kt | 4 +- loaderspack/src/main/res/values/colors.xml | 10 --- 17 files changed, 85 insertions(+), 80 deletions(-) delete mode 100644 loaderspack/src/main/res/values/colors.xml diff --git a/app/src/main/res/layout/activity_main_circular.xml b/app/src/main/res/layout/activity_main_circular.xml index cc2e969..8364304 100644 --- a/app/src/main/res/layout/activity_main_circular.xml +++ b/app/src/main/res/layout/activity_main_circular.xml @@ -87,9 +87,9 @@ app:circularsticks_noOfSticks="32" app:circularsticks_outerCircleRadius="80dp" app:circularsticks_secondShadowColor="#77000000" - app:circularsticks_selectedStickColor="@color/black" + app:circularsticks_selectedStickColor="@android:color/black" app:circularsticks_showRunningShadow="true" - app:circularsticks_stickColor="@color/grey" + app:circularsticks_stickColor="@android:color/darker_gray" app:circularsticks_viewBackgroundColor="@color/white" /> diff --git a/app/src/main/res/layout/activity_main_circular_rotating.xml b/app/src/main/res/layout/activity_main_circular_rotating.xml index db9c270..8e28262 100644 --- a/app/src/main/res/layout/activity_main_circular_rotating.xml +++ b/app/src/main/res/layout/activity_main_circular_rotating.xml @@ -70,7 +70,7 @@ app:rotatingsticks_innerCircleRadius="60dp" app:rotatingsticks_noOfSticks="50" app:rotatingsticks_outerCircleRadius="80dp" - app:rotatingsticks_stickColor="@color/grey" + app:rotatingsticks_stickColor="@android:color/darker_gray" app:rotatingsticks_viewBackgroundColor="@color/white" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main_clock.xml b/app/src/main/res/layout/activity_main_clock.xml index 2288073..cf7df6c 100644 --- a/app/src/main/res/layout/activity_main_clock.xml +++ b/app/src/main/res/layout/activity_main_clock.xml @@ -32,15 +32,15 @@ android:layout_height="wrap_content" app:clock_animSpeedMultiplier="0.5" android:layout_margin="16dp" - app:clock_bigCircleColor="@color/black" + app:clock_bigCircleColor="@android:color/black" app:clock_bigCircleRadius="100dp" - app:clock_hourHandColor="@color/grey" + app:clock_hourHandColor="@android:color/darker_gray" app:clock_hourHandLength="50dp" - app:clock_innerCircleColor="@color/grey" + app:clock_innerCircleColor="@android:color/darker_gray" app:clock_innerCircleRadius="5dp" - app:clock_minuteHandColor="@color/grey" + app:clock_minuteHandColor="@android:color/darker_gray" app:clock_minuteHandLength="80dp" - app:clock_outerCircleBorderColor="@color/grey" + app:clock_outerCircleBorderColor="@android:color/darker_gray" app:clock_outerCircleBorderWidth="10dp" /> diff --git a/app/src/main/res/layout/activity_main_multipleripple.xml b/app/src/main/res/layout/activity_main_multipleripple.xml index 4ec98ea..ef738c0 100644 --- a/app/src/main/res/layout/activity_main_multipleripple.xml +++ b/app/src/main/res/layout/activity_main_multipleripple.xml @@ -91,7 +91,7 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" app:multipleripple_animDuration="4000" - app:multipleripple_circleColor="@color/grey" + app:multipleripple_circleColor="@android:color/darker_gray" app:multipleripple_circleInitialRadius="36dp" app:multipleripple_fromAlpha="0.6" app:multipleripple_interpolator="@android:anim/linear_interpolator" diff --git a/app/src/main/res/layout/main_curves.xml b/app/src/main/res/layout/main_curves.xml index 1d5bd52..55b4348 100644 --- a/app/src/main/res/layout/main_curves.xml +++ b/app/src/main/res/layout/main_curves.xml @@ -71,7 +71,7 @@ android:layout_height="wrap_content" android:layout_margin="16dp" app:curves_animDuration="1000" - app:curves_curveColor="@color/grey" + app:curves_curveColor="@android:color/darker_gray" app:curves_curveSweepAngle="150" app:curves_curveWidth="5dp" app:curves_distanceBetweenCurves="5dp" diff --git a/app/src/main/res/layout/main_fidget.xml b/app/src/main/res/layout/main_fidget.xml index b6e11f0..d473ea8 100644 --- a/app/src/main/res/layout/main_fidget.xml +++ b/app/src/main/res/layout/main_fidget.xml @@ -7,58 +7,70 @@ android:gravity="center" android:orientation="vertical"> - - + android:layout_margin="8dp" + app:fidget_animDuration="3000" + app:fidget_bodyColor="@color/blue_selected" + app:fidget_fidgetRadius="30dp" + app:fidget_interpolator="@android:anim/accelerate_decelerate_interpolator" + app:fidget_noOfRotation="10" + app:fidget_sideCirclesColor="@android:color/darker_gray" /> + android:layout_margin="8dp" + app:fidget_animDuration="1000" + app:fidget_bodyColor="@android:color/black" + app:fidget_fidgetRadius="25dp" + app:fidget_interpolator="@android:anim/linear_interpolator" + app:fidget_noOfRotation="1" + app:fidget_sideCirclesColor="@color/darkmagenta" /> \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f899f3d..fb83572 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -13,11 +13,14 @@ #FFC200 #77FFC200 + #0000ff #2196F3 #BBDEFB #55A9A9A9 + #8B008B + @color/red @@ -34,7 +37,7 @@ @color/red @color/amber @color/green - @color/grey + @android:color/darker_gray diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/ArcView.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/ArcView.kt index 3eaea19..ffe2d52 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/ArcView.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/ArcView.kt @@ -21,7 +21,7 @@ class ArcView : View { var sweepAngle: Float = 180.0f - var arcColor: Int = resources.getColor(R.color.red) + var arcColor: Int = resources.getColor(android.R.color.holo_red_dark) var drawOnlyStroke: Boolean = true private val paint: Paint = Paint() @@ -64,7 +64,7 @@ class ArcView : View { this.startAngle = typedArray.getFloat(R.styleable.ArcView_startAngle, 0.0f) this.sweepAngle = typedArray.getFloat(R.styleable.ArcView_sweepAngle, 180.0f) - this.arcColor = typedArray.getColor(R.styleable.ArcView_arcColor, resources.getColor(R.color.red)) + this.arcColor = typedArray.getColor(R.styleable.ArcView_arcColor, resources.getColor(android.R.color.holo_red_dark)) this.drawOnlyStroke = typedArray.getBoolean(R.styleable.ArcView_drawOnlyStroke, true) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/CircularSticksBaseView.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/CircularSticksBaseView.kt index 442eccf..e9872f8 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/CircularSticksBaseView.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/basicviews/CircularSticksBaseView.kt @@ -19,7 +19,7 @@ open class CircularSticksBaseView : View, LoaderContract { var outerCircleRadius: Float = 200.0f var innerCircleRadius: Float = 100.0f - open var sticksColor: Int = resources.getColor(R.color.grey) + open var sticksColor: Int = resources.getColor(android.R.color.darker_gray) var viewBackgroundColor: Int = resources.getColor(android.R.color.white) protected lateinit var sticksPaint: Paint @@ -64,7 +64,7 @@ open class CircularSticksBaseView : View, LoaderContract { this.sticksColor = typedArray - .getColor(R.styleable.CircularSticksBaseView_sticksbase_stickColor, resources.getColor(R.color.grey)) + .getColor(R.styleable.CircularSticksBaseView_sticksbase_stickColor, resources.getColor(android.R.color.darker_gray)) this.viewBackgroundColor = typedArray .getColor(R.styleable.CircularSticksBaseView_sticksbase_viewBackgroundColor, resources.getColor(android.R.color.white)) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ArcProgressLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ArcProgressLoader.kt index e20ad77..273ad3d 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ArcProgressLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ArcProgressLoader.kt @@ -25,9 +25,9 @@ class ArcProgressLoader : View, LoaderContract { field = if (value > 360) (value % 360) else value } - var arcColorsArray: IntArray = intArrayOf(resources.getColor(R.color.red), - resources.getColor(R.color.amber), - resources.getColor(R.color.green)) + var arcColorsArray: IntArray = intArrayOf(resources.getColor(android.R.color.holo_red_dark), + resources.getColor(android.R.color.holo_orange_light), + resources.getColor(android.R.color.holo_green_light)) private val paint: Paint = Paint() private var centerPoint: Float = 0.0f diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/CircularSticksLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/CircularSticksLoader.kt index 2e3f941..c75576c 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/CircularSticksLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/CircularSticksLoader.kt @@ -14,7 +14,7 @@ import com.agrawalsuneet.loaderspack.basicviews.CircularSticksBaseView */ class CircularSticksLoader : CircularSticksBaseView { - override var sticksColor: Int = resources.getColor(R.color.grey) + override var sticksColor: Int = resources.getColor(android.R.color.darker_gray) set(defaultColor) { field = defaultColor if (defaultStickPaint != null) { @@ -22,7 +22,7 @@ class CircularSticksLoader : CircularSticksBaseView { } } - open var selectedStickColor: Int = resources.getColor(R.color.black) + open var selectedStickColor: Int = resources.getColor(android.R.color.black) set(selectedColor) { field = selectedColor if (selectedStickPaint != null) { @@ -112,9 +112,9 @@ class CircularSticksLoader : CircularSticksBaseView { this.sticksColor = typedArray - .getColor(R.styleable.CircularSticksLoader_circularsticks_stickColor, resources.getColor(R.color.grey)) + .getColor(R.styleable.CircularSticksLoader_circularsticks_stickColor, resources.getColor(android.R.color.darker_gray)) this.selectedStickColor = typedArray - .getColor(R.styleable.CircularSticksLoader_circularsticks_selectedStickColor, resources.getColor(R.color.black)) + .getColor(R.styleable.CircularSticksLoader_circularsticks_selectedStickColor, resources.getColor(android.R.color.black)) this.viewBackgroundColor = typedArray .getColor(R.styleable.CircularSticksLoader_circularsticks_viewBackgroundColor, resources.getColor(android.R.color.white)) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ClockLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ClockLoader.kt index 09c659c..6a3744a 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ClockLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/ClockLoader.kt @@ -46,31 +46,31 @@ class ClockLoader : View, LoaderContract { initValues() } - var outerCircleBorderColor: Int = resources.getColor(R.color.grey) + var outerCircleBorderColor: Int = resources.getColor(android.R.color.darker_gray) set(value) { field = value initPaints() } - var bigCircleColor: Int = resources.getColor(R.color.black) + var bigCircleColor: Int = resources.getColor(android.R.color.black) set(value) { field = value initPaints() } - var hourHandColor: Int = resources.getColor(R.color.grey) + var hourHandColor: Int = resources.getColor(android.R.color.darker_gray) set(value) { field = value initPaints() } - var minuteHandColor: Int = resources.getColor(R.color.grey) + var minuteHandColor: Int = resources.getColor(android.R.color.darker_gray) set(value) { field = value initPaints() } - var innerCircleColor: Int = resources.getColor(R.color.grey) + var innerCircleColor: Int = resources.getColor(android.R.color.darker_gray) set(value) { field = value initPaints() @@ -124,15 +124,15 @@ class ClockLoader : View, LoaderContract { .getDimension(R.styleable.ClockLoader_clock_minuteHandLength, 300.0f) this.outerCircleBorderColor = typedArray - .getColor(R.styleable.ClockLoader_clock_outerCircleBorderColor, resources.getColor(R.color.grey)) + .getColor(R.styleable.ClockLoader_clock_outerCircleBorderColor, resources.getColor(android.R.color.darker_gray)) this.bigCircleColor = typedArray - .getColor(R.styleable.ClockLoader_clock_bigCircleColor, resources.getColor(R.color.black)) + .getColor(R.styleable.ClockLoader_clock_bigCircleColor, resources.getColor(android.R.color.black)) this.innerCircleColor = typedArray - .getColor(R.styleable.ClockLoader_clock_innerCircleColor, resources.getColor(R.color.grey)) + .getColor(R.styleable.ClockLoader_clock_innerCircleColor, resources.getColor(android.R.color.darker_gray)) this.hourHandColor = typedArray - .getColor(R.styleable.ClockLoader_clock_hourHandColor, resources.getColor(R.color.grey)) + .getColor(R.styleable.ClockLoader_clock_hourHandColor, resources.getColor(android.R.color.darker_gray)) this.minuteHandColor = typedArray - .getColor(R.styleable.ClockLoader_clock_minuteHandColor, resources.getColor(R.color.grey)) + .getColor(R.styleable.ClockLoader_clock_minuteHandColor, resources.getColor(android.R.color.darker_gray)) this.animSpeedMultiplier = typedArray .getFloat(R.styleable.ClockLoader_clock_animSpeedMultiplier, 1.0f) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt index ee98f0c..d7df1a5 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/FidgetLoader.kt @@ -39,7 +39,7 @@ class FidgetLoader : LinearLayout, LoaderContract { initView() } - constructor(context: Context?, fidgetRadius: Int, bodyColor: Int, sideCirclesColor: Int) : super(context) { + constructor(context: Context, fidgetRadius: Int, bodyColor: Int, sideCirclesColor: Int) : super(context) { this.fidgetRadius = fidgetRadius this.bodyColor = bodyColor this.sideCirclesColor = sideCirclesColor @@ -50,7 +50,7 @@ class FidgetLoader : LinearLayout, LoaderContract { override fun initAttributes(attrs: AttributeSet) { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FidgetLoader, 0, 0) - fidgetRadius = typedArray.getInteger(R.styleable.FidgetLoader_fidget_fidgetRadius, 100) + fidgetRadius = typedArray.getDimensionPixelSize(R.styleable.FidgetLoader_fidget_fidgetRadius, 100) bodyColor = typedArray.getColor(R.styleable.FidgetLoader_fidget_bodyColor, resources.getColor(android.R.color.holo_red_light)) @@ -63,7 +63,7 @@ class FidgetLoader : LinearLayout, LoaderContract { animDuration = typedArray.getInt(R.styleable.FidgetLoader_fidget_animDuration, 3000) - this.interpolator = AnimationUtils.loadInterpolator(context, + interpolator = AnimationUtils.loadInterpolator(context, typedArray.getResourceId(R.styleable.FidgetLoader_fidget_interpolator, android.R.anim.accelerate_decelerate_interpolator)) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/MultipleRippleLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/MultipleRippleLoader.kt index 5ed4a91..5f710fa 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/MultipleRippleLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/MultipleRippleLoader.kt @@ -48,7 +48,7 @@ class MultipleRippleLoader : RippleLoader { .getDimensionPixelSize(R.styleable.MultipleRippleLoader_multipleripple_circleInitialRadius, 40) circleColor = typedArray.getColor(R.styleable.MultipleRippleLoader_multipleripple_circleColor, - resources.getColor(R.color.red)) + resources.getColor(android.R.color.holo_red_dark)) noOfRipples = typedArray.getInteger(R.styleable.MultipleRippleLoader_multipleripple_noOfRipples, 3) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RippleLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RippleLoader.kt index 9b5b320..7e31879 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RippleLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RippleLoader.kt @@ -22,7 +22,7 @@ open class RippleLoader : LinearLayout, LoaderContract { initView() } - var circleColor: Int = resources.getColor(R.color.red) + var circleColor: Int = resources.getColor(android.R.color.holo_red_dark) set(value) { field = value initView() @@ -59,7 +59,7 @@ open class RippleLoader : LinearLayout, LoaderContract { .getDimensionPixelSize(R.styleable.RippleLoader_ripple_circleInitialRadius, 40) circleColor = typedArray.getColor(R.styleable.RippleLoader_ripple_circleColor, - resources.getColor(R.color.red)) + resources.getColor(android.R.color.holo_red_dark)) fromAlpha = typedArray.getFloat(R.styleable.RippleLoader_ripple_fromAlpha, 0.9f) diff --git a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RotatingCircularSticksLoader.kt b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RotatingCircularSticksLoader.kt index 586028b..1dea2cf 100644 --- a/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RotatingCircularSticksLoader.kt +++ b/loaderspack/src/main/java/com/agrawalsuneet/loaderspack/loaders/RotatingCircularSticksLoader.kt @@ -21,7 +21,7 @@ class RotatingCircularSticksLoader : LinearLayout, LoaderContract { var outerCircleRadius: Float = 200.0f var innerCircleRadius: Float = 100.0f - var sticksColor: Int = resources.getColor(R.color.grey) + var sticksColor: Int = resources.getColor(android.R.color.darker_gray) var viewBackgroundColor: Int = resources.getColor(android.R.color.white) var animDuration: Int = 5000 @@ -64,7 +64,7 @@ class RotatingCircularSticksLoader : LinearLayout, LoaderContract { this.sticksColor = typedArray - .getColor(R.styleable.RotatingCircularSticksLoader_rotatingsticks_stickColor, resources.getColor(R.color.grey)) + .getColor(R.styleable.RotatingCircularSticksLoader_rotatingsticks_stickColor, resources.getColor(android.R.color.darker_gray)) this.viewBackgroundColor = typedArray .getColor(R.styleable.RotatingCircularSticksLoader_rotatingsticks_viewBackgroundColor, resources.getColor(android.R.color.white)) diff --git a/loaderspack/src/main/res/values/colors.xml b/loaderspack/src/main/res/values/colors.xml deleted file mode 100644 index 3914a3f..0000000 --- a/loaderspack/src/main/res/values/colors.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - #000000 - #A9A9A9 - - #0000ff - #ff0000 - #FFC200 - #00e500 - From d0aa817642e8505002087b3d27085fab80b650b0 Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Sun, 23 Sep 2018 00:41:28 +0530 Subject: [PATCH 6/7] updated readme --- README.md | 51 ++++++++++++++++++- .../com/agrawalsuneet/loaders/MainActivity.kt | 19 ++++++- .../loaders/MainActivityJava.java | 22 +++++--- loaderspack/build.gradle | 6 +-- 4 files changed, 85 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 31c78f6..ca2e01c 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,16 @@ latest version : [ ![Download](https://api.bintray.com/packages/agrawalsuneet/an ![arcprogressloader](https://user-images.githubusercontent.com/12999622/45809206-3fe05800-bce5-11e8-90ef-f68e46de64cc.gif) +### FidgetLoader +![arcprogressloader](https://user-images.githubusercontent.com/12999622/45809206-3fe05800-bce5-11e8-90ef-f68e46de64cc.gif) + + Check all other loaders [here](https://agrawalsuneet.github.io/agrawalsuneet/opensourcecontribution/) ## How To use include below dependency in build.gradle of application and compile it ``` -implementation 'com.agrawalsuneet.androidlibs:loaderspack:0.7' +implementation 'com.agrawalsuneet.androidlibs:loaderspack:0.8' ``` ### ClockLoader @@ -396,6 +400,50 @@ implementation 'com.agrawalsuneet.androidlibs:loaderspack:0.7' ``` +##### Through XML +``` + +``` +##### Through Code +* Kotlin +``` + val fidgetLoader = FidgetLoader(this, + 20, + ContextCompat.getColor(this, R.color.blue_selected), + ContextCompat.getColor(this, R.color.amber)) + .apply { + animDuration = 3000 + noOfRotation = 1 + interpolator = BounceInterpolator() + } + + containerLayout.addView(fidgetLoader) +``` + +* Java +``` + FidgetLoader fidgetLoader = new FidgetLoader(this, + 20, + ContextCompat.getColor(this, R.color.blue_selected), + ContextCompat.getColor(this, R.color.amber)); + + fidgetLoader.setAnimDuration(3000); + fidgetLoader.setNoOfRotation(1); + fidgetLoader.setInterpolator(new BounceInterpolator()); + + container.addView(fidgetLoader); +``` + + +### FidgetLoader ##### Through XML ``` Date: Sun, 23 Sep 2018 01:07:14 +0530 Subject: [PATCH 7/7] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca2e01c..d7a3e07 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ latest version : [ ![Download](https://api.bintray.com/packages/agrawalsuneet/an ### FidgetLoader -![arcprogressloader](https://user-images.githubusercontent.com/12999622/45809206-3fe05800-bce5-11e8-90ef-f68e46de64cc.gif) +![fidgetloader](https://user-images.githubusercontent.com/12999622/45921114-dfac0a80-becc-11e8-8a1e-8c8d78c31dd4.gif) Check all other loaders [here](https://agrawalsuneet.github.io/agrawalsuneet/opensourcecontribution/)