From b56056e3517043850e1ca7274d1af31cfb79751c Mon Sep 17 00:00:00 2001 From: hi-manshu Date: Thu, 10 Jan 2019 17:59:23 +0530 Subject: [PATCH] Added : Max - Angle Values --- .gitignore | 2 +- app/.gitignore | 10 +++ .../java/com/mindorks/app/MainActivity.kt | 4 + app/src/main/res/layout/activity_main.xml | 10 +-- radialprogressbar/.gitignore | 10 +++ .../java/com/mindorks/RadialProgressBar.kt | 78 +++++++++++++++---- .../main/java/com/mindorks/onClickListener.kt | 7 ++ .../src/main/res/values/attrs.xml | 3 + 8 files changed, 104 insertions(+), 20 deletions(-) create mode 100644 radialprogressbar/src/main/java/com/mindorks/onClickListener.kt diff --git a/.gitignore b/.gitignore index fd45b12..dfc9e47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ *.iml .gradle /local.properties -/.idea/caches/build_file_checksums.ser /.idea/libraries /.idea/modules.xml /.idea/workspace.xml @@ -9,3 +8,4 @@ /build /captures .externalNativeBuild +/.idea \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore index 796b96d..dfc9e47 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store /build +/captures +.externalNativeBuild +/.idea \ No newline at end of file diff --git a/app/src/main/java/com/mindorks/app/MainActivity.kt b/app/src/main/java/com/mindorks/app/MainActivity.kt index 6af8186..673a424 100644 --- a/app/src/main/java/com/mindorks/app/MainActivity.kt +++ b/app/src/main/java/com/mindorks/app/MainActivity.kt @@ -2,6 +2,7 @@ package com.mindorks.app import android.os.Bundle import android.support.v7.app.AppCompatActivity +import android.util.Log import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { @@ -9,6 +10,9 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + progress.useRoundedCorners(false) + progress.setMaxProgressValues(200,200,200) + progress.setProgressValues(100,100,100) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 056a150..e63dde4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="#000" + android:background="#fff" tools:context=".MainActivity"> @@ -11,13 +11,13 @@ android:layout_width="200dp" android:layout_height="200dp" android:id="@+id/progress" - app:outerProgress="40" - app:innerProgress="40" - app:centerProgress="40" app:useRoundedCorner="true" app:centerProgressStartAngle="270" app:innerProgressStartAngle="270" - app:isAnimationOn="true" + app:innerMaxProgress="2000" + app:outerMaxProgress="200" + app:centerMaxProgress="500" + app:isAnimationOn="false" app:outerProgressStartAngle="270" /> diff --git a/radialprogressbar/.gitignore b/radialprogressbar/.gitignore index 796b96d..dfc9e47 100644 --- a/radialprogressbar/.gitignore +++ b/radialprogressbar/.gitignore @@ -1 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store /build +/captures +.externalNativeBuild +/.idea \ No newline at end of file diff --git a/radialprogressbar/src/main/java/com/mindorks/RadialProgressBar.kt b/radialprogressbar/src/main/java/com/mindorks/RadialProgressBar.kt index c8d65eb..bf80454 100644 --- a/radialprogressbar/src/main/java/com/mindorks/RadialProgressBar.kt +++ b/radialprogressbar/src/main/java/com/mindorks/RadialProgressBar.kt @@ -36,7 +36,7 @@ class RadialProgressBar : View { //Data of the Outer View private var mStartAngleOuterView = 270 - private var mOuterProgress = 30 + private var mOuterProgress = 0 private var mSweepAngleOuterView = 0 private var mAnimationDurationOuterView = 400 private var mMaxProgressOuterView = 100 @@ -48,7 +48,7 @@ class RadialProgressBar : View { private var mSweepAngleCenterView = 0 private var mAnimationDurationCenterView = 400 private var mMaxProgressCenterView = 100 - private var mCenterProgress = 30 + private var mCenterProgress = 0 private var mProgressColorCenterView = Color.parseColor("#c2ff07") private var mPaintCenterView = Paint(Paint.ANTI_ALIAS_FLAG) @@ -56,7 +56,7 @@ class RadialProgressBar : View { //Data of the Inner View private var mStartAngleInnerView = 270 private var mSweepAngleInnerView = 0 - private var mInnerProgress = 30 + private var mInnerProgress = 0 private var mAnimationDurationInnerView = 400 private var mMaxProgressInnerView = 100 private var mProgressColorInnerView = Color.parseColor("#0dffab") @@ -86,8 +86,14 @@ class RadialProgressBar : View { mStartAngleCenterView = a.getInteger(R.styleable.RadialProgressBar_centerProgressStartAngle, mStartAngleCenterView) mStartAngleInnerView = a.getInteger(R.styleable.RadialProgressBar_innerProgressStartAngle, mStartAngleInnerView) + mMaxProgressOuterView = a.getInteger(R.styleable.RadialProgressBar_outerMaxProgress, mMaxProgressOuterView) + mMaxProgressInnerView = a.getInteger(R.styleable.RadialProgressBar_innerMaxProgress, mMaxProgressInnerView) + mMaxProgressCenterView = a.getInteger(R.styleable.RadialProgressBar_centerMaxProgress, mMaxProgressCenterView) a.recycle() setAnimationInProgressView(isAnimationOn) + setMaxProgressOuterView(mMaxProgressOuterView) + setMaxProgressInnerView(mMaxProgressInnerView) + setMaxProgressCenterView(mMaxProgressCenterView) setOuterProgress(mOuterProgress) setOuterProgressColor(mProgressColorOuterView) setInnerProgress(mInnerProgress) @@ -100,20 +106,13 @@ class RadialProgressBar : View { setStartAngleOuterView(mStartAngleOuterView) } - private fun setAnimationInProgressView(animationOn: Boolean) { - if (!animationOn) { - mAnimationDurationOuterView = 0 - mAnimationDurationInnerView = 0 - mAnimationDurationCenterView = 0 - } - } private fun drawInnerCircle(canvas: Canvas?) { val diameter = Math.min(mViewWidth, mViewHeight) val paddingView = (diameter / 16.0).toFloat() val stroke = (diameter / 8).toFloat() - val addVal = (stroke * 2) + 4f - val subVal = ((stroke * 2) + paddingView + 4f) + val addVal = (stroke * 2) + 8f + val subVal = ((stroke * 2) + paddingView + 8f) val oval = RectF(paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal) mPaintInnerView.color = mProgressColorInnerView mPaintInnerView.strokeWidth = stroke @@ -129,8 +128,8 @@ class RadialProgressBar : View { val diameter = Math.min(mViewWidth, mViewHeight) val paddingView = (diameter / 16.0).toFloat() val stroke = (diameter / 8).toFloat() - val addVal = stroke + 2f - val subVal = (stroke + paddingView + 2f) + val addVal = stroke + 4f + val subVal = (stroke + paddingView + 4f) val oval = RectF(paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal) mPaintCenterView.color = mProgressColorCenterView mPaintCenterView.strokeWidth = stroke @@ -200,18 +199,47 @@ class RadialProgressBar : View { return this.mStartAngleCenterView } + fun getMaxProgressInnerView(): Int { + return this.mMaxProgressInnerView + } + + fun getMaxProgressOuterView(): Int { + return this.mMaxProgressOuterView + } + + fun getMaxProgressCenterView(): Int { + return this.mMaxProgressCenterView + } + fun setStartAngleCenterView(angle: Int) { mStartAngleCenterView = angle + invalidate() } fun setStartAngleOuterView(angle: Int) { mStartAngleOuterView = angle + invalidate() } fun setStartAngleInnerView(angle: Int) { mStartAngleInnerView = angle + invalidate() + } + + fun setMaxProgressOuterView(max: Int) { + mMaxProgressOuterView = max + invalidate() } + fun setMaxProgressInnerView(max: Int) { + mMaxProgressInnerView = max + invalidate() + } + + fun setMaxProgressCenterView(max: Int) { + mMaxProgressCenterView = max + invalidate() + } fun setOuterProgress(progress: Int) { if (progress != 0) mOuterProgress = progress @@ -233,11 +261,33 @@ class RadialProgressBar : View { invalidate() } + private fun setAnimationInProgressView(animationOn: Boolean) { + if (!animationOn) { + mAnimationDurationOuterView = 0 + mAnimationDurationInnerView = 0 + mAnimationDurationCenterView = 0 + } + } + fun useRoundedCorners(roundedCorners: Boolean) { mRoundedCorners = roundedCorners invalidate() } + fun setProgressValues(innerProgress: Int, centerProgress: Int, outerProgress: Int) { + setInnerProgress(innerProgress) + setCenterProgress(centerProgress) + setOuterProgress(outerProgress) + invalidate() + + } + fun setMaxProgressValues(innerProgress: Int, centerProgress: Int, outerProgress: Int) { + setMaxProgressInnerView(innerProgress) + setMaxProgressCenterView(centerProgress) + setMaxProgressOuterView(outerProgress) + invalidate() + } + fun setInnerProgress(progress: Int) { if (progress != 0) mInnerProgress = progress val animator = diff --git a/radialprogressbar/src/main/java/com/mindorks/onClickListener.kt b/radialprogressbar/src/main/java/com/mindorks/onClickListener.kt new file mode 100644 index 0000000..2173a1a --- /dev/null +++ b/radialprogressbar/src/main/java/com/mindorks/onClickListener.kt @@ -0,0 +1,7 @@ +package com.mindorks + +interface onClickListener { + + fun onClickListener(innerProgress: Int, centerProgress: Int, outerProgress: Int) +} + diff --git a/radialprogressbar/src/main/res/values/attrs.xml b/radialprogressbar/src/main/res/values/attrs.xml index 906900a..3ca7791 100644 --- a/radialprogressbar/src/main/res/values/attrs.xml +++ b/radialprogressbar/src/main/res/values/attrs.xml @@ -5,15 +5,18 @@ + + +