Skip to content

Instantly share code, notes, and snippets.

@SouravKumarPandit
Last active August 9, 2018 05:34
Show Gist options
  • Save SouravKumarPandit/72dd23d706809f11ed71e10f35335c46 to your computer and use it in GitHub Desktop.
Save SouravKumarPandit/72dd23d706809f11ed71e10f35335c46 to your computer and use it in GitHub Desktop.
package com.application.limitless.sourav.dashletsproject.protectorChart;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.ColorInt;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import com.application.limitless.sourav.dashletsproject.R;
public class CLProtractorView extends View {
private static final int MAX = 180;
private RectF mRoundTextRect = new RectF();
private RectF mArcViewRect = new RectF();
private static final int ANGLE_OFFSET_MIN = 180;
private static final int ANGLE_OFFSET_MAX = 180;
private Paint mArcPaint;
private Paint mArcProgressPaint;
private Paint mTickPaint;
private Paint mTickProgressPaint;
private Paint mTickTextPaint;
private Paint mTickTextColoredPaint;
private int mArcRadius = 0;
private int mArcWidth = 5;
private String sCenterText;
private String sSubText;
private int iCenterTextColor;
private int iSubTextColor;
private int mArcProgressWidth = 5;
private boolean mRoundedEdges = false;
ObjectAnimator progressAnimator;
private float arcTextSpacing = 5;
private int mTranslateX;
private int mTranslateY;
private int mAngleTextSize = 12;
private int mTickOffset = 12;
private int mTickLength = 10;
private int mTickWidth = 1;
private int mTickProgressWidth = 1;
private int mAngle = 0;
private boolean mTouchInside = true;
private boolean mTouchEnable = true;
private TicksBetweenLabel mTicksBetweenLabel = TicksBetweenLabel.TWO;
private int mTickIntervals = 15;//hint give 15 and 30 for better angle looking view
private double mTouchAngle = 0;
private float mTouchIgnoreRadius;
private Paint mCenterTextPaint;
private Paint mSubTextPaint;
private Rect mTextRect;
private Rect mSubTextRect;
private float mCenterTextSize = 45;
private float mSubTextSize = 25;
//for Event listening
private OnProtractorViewChangeListener mOnProtractorViewChangeListener = null;
private int arcColor;
private int arcProgressColor;
private double MIN_VALUE = 0;
private double MAX_VALUE = 180;
private float chartvalue;
private int tickProgressColor;
private int tickTextColor;
private int tickPaintColor;
private int tickedTextColored;
private boolean animatorEnable = true;
private boolean tickEnable;
//Interface for event listener
public interface OnProtractorViewChangeListener {
void onProgressChanged(CLProtractorView protractorView, int progress, boolean fromUser);
void onStartTrackingTouch(CLProtractorView protractorView);
void onStopTrackingTouch(CLProtractorView protractorView);
void onSelectedBarTouch(String format, float xPos, float yPos);
}
public enum TicksBetweenLabel {
ZERO, ONE, TWO, THREE, FOUR
}
public CLProtractorView(Context context)
{
super(context);
init(context, null, 0);
}
public CLProtractorView(Context context, AttributeSet attrs)
{
super(context, attrs);
init(context, attrs, R.attr.protractorViewStyle);
}
public CLProtractorView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
private void init(Context context, AttributeSet attrs, int defStyle)
{
//size of arc and progress arc
mArcProgressWidth = mArcWidth;
arcColor = 0xa2353236;
arcProgressColor = 0xff5aa75a;
tickPaintColor = arcColor;
tickProgressColor = arcProgressColor;
tickTextColor = arcColor;
tickedTextColored = arcProgressColor;
iCenterTextColor = 0xFFFFD6B8;
iSubTextColor = 0xFFE6B54D;
mCenterTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mCenterTextSize, getResources().getDisplayMetrics());
mSubTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mSubTextSize, getResources().getDisplayMetrics());
mAngleTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mAngleTextSize, getResources().getDisplayMetrics());
mAngle = (mAngle > MAX) ? MAX : ((mAngle < 0) ? 0 : mAngle);
mArcPaint = new Paint();
mArcPaint.setColor(arcColor);
mArcPaint.setAntiAlias(true);
mArcPaint.setStyle(Paint.Style.STROKE);
mArcPaint.setStrokeWidth(mArcWidth);
mArcPaint.setDither(true);
mArcProgressPaint = new Paint();
mArcProgressPaint.setColor(arcProgressColor);
mArcProgressPaint.setAntiAlias(true);
mArcProgressPaint.setStyle(Paint.Style.STROKE);
mArcProgressPaint.setStrokeWidth(mArcProgressWidth);
mArcProgressPaint.setDither(true);
if (mRoundedEdges)
{
mArcPaint.setStrokeCap(Paint.Cap.ROUND);
mArcProgressPaint.setStrokeCap(Paint.Cap.ROUND);
}
mTickPaint = new Paint();
mTickPaint.setColor(tickPaintColor);
mTickPaint.setAntiAlias(true);
mTickPaint.setStyle(Paint.Style.STROKE);
mTickPaint.setStrokeWidth(mTickWidth);
mTickPaint.setStrokeCap(Paint.Cap.ROUND);
mTickProgressPaint = new Paint();
mTickProgressPaint.setColor(tickProgressColor);
mTickProgressPaint.setAntiAlias(true);
mTickProgressPaint.setStyle(Paint.Style.STROKE);
mTickProgressPaint.setStrokeWidth(mTickProgressWidth);
mTickProgressPaint.setStrokeCap(Paint.Cap.ROUND);
mTickTextPaint = new Paint();
mTickTextPaint.setColor(tickTextColor);
mTickTextPaint.setAntiAlias(true);
mTickTextPaint.setStyle(Paint.Style.FILL);
mTickTextPaint.setTextSize(mAngleTextSize);
mTickTextPaint.setTextAlign(Paint.Align.CENTER);
mTickTextColoredPaint = new Paint();
mTickTextColoredPaint.setColor(tickedTextColored);
mTickTextColoredPaint.setAntiAlias(true);
mTickTextColoredPaint.setStyle(Paint.Style.FILL);
mTickTextColoredPaint.setTextSize(mAngleTextSize);
mTickTextColoredPaint.setTextAlign(Paint.Align.CENTER);
mTickOffset = (int) mTickTextColoredPaint.getTextSize();
mCenterTextPaint = new Paint();
mCenterTextPaint.setColor(iCenterTextColor);
mCenterTextPaint.setAntiAlias(true);
mCenterTextPaint.setStyle(Paint.Style.FILL);
mCenterTextPaint.setTextSize(mCenterTextSize);
mSubTextPaint = new Paint();
mSubTextPaint.setColor(iSubTextColor);
mSubTextPaint.setAntiAlias(true);
mSubTextPaint.setStyle(Paint.Style.FILL);
mSubTextPaint.setTextSize(mSubTextSize);
mTextRect = new Rect();
mSubTextRect = new Rect();
sCenterText = String.valueOf(mAngle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
int min = Math.min(width, height);
height = min / 2;
float top = 0;
float left = 0;
int arcDiameter = 0;
int tickEndToArc = (mTickOffset + mTickLength + mArcWidth);
arcDiameter = (int) (min - 2.5 * tickEndToArc);
mArcRadius = (int) (arcDiameter / 2 );
top = height - mArcRadius;
left = width / 2 - mArcRadius;
mRoundTextRect.set(left, top, left + arcDiameter, top + arcDiameter);
mArcViewRect.set(left + mArcWidth, top + mArcWidth, left + arcDiameter - mArcWidth, top + arcDiameter - mArcWidth);
mTranslateX = (int) mRoundTextRect.centerX();
mTranslateY = (int) mRoundTextRect.centerY();
setTouchInside(mTouchInside);
setMeasuredDimension(width, height + tickEndToArc);
}
@Override
protected void onDraw(Canvas canvas)
{
canvas.save();
if (sCenterText != null || mCenterTextPaint.getTextSize() == 0)
{
mCenterTextPaint.getTextBounds(sCenterText, 0, sCenterText.length(), mTextRect);
int xPos = canvas.getWidth() / 2 - mTextRect.width() / 2;
int yPos = (int) ((mRoundTextRect.centerY() * 0.75f) - ((mCenterTextPaint.descent() + mCenterTextPaint.ascent()) / 2));
canvas.drawText(sCenterText, xPos, yPos, mCenterTextPaint);
}
if (sSubText != null || mSubTextPaint.getTextSize() == 0)
{
mSubTextPaint.getTextBounds(sSubText, 0, sSubText.length(), mSubTextRect);
int xSubPos = canvas.getWidth() / 2 - mSubTextRect.width() / 2;
int ySubPos = (int) (mRoundTextRect.centerY() * 0.8f + (mCenterTextPaint.getTextSize() / 1.5) - ((mSubTextPaint.descent() + mSubTextPaint.ascent()) / 2));
canvas.drawText(sSubText, xSubPos, ySubPos, mSubTextPaint);
}
canvas.drawArc(mArcViewRect, ANGLE_OFFSET_MIN, ANGLE_OFFSET_MAX, false, mArcPaint);
canvas.drawArc(mArcViewRect, ANGLE_OFFSET_MIN, mAngle, false, mArcProgressPaint);
canvas.restore();
double slope, startTickX, startTickY, endTickX, endTickY, midTickX, midTickY, thetaInRadians;
double radiusOffset = mArcRadius + mTickOffset + arcTextSpacing;
int count = mTicksBetweenLabel.ordinal();
if (!(mTickIntervals <= 0))
for (int i = 360; i >= 180; i -= mTickIntervals)
{
canvas.save();
if (count == mTicksBetweenLabel.ordinal())
{
//for text
canvas.translate(mRoundTextRect.centerX(), mRoundTextRect.centerY());
thetaInRadians = Math.toRadians(i);
slope = Math.tan(thetaInRadians);
startTickX = (radiusOffset * Math.cos(thetaInRadians));
midTickX = startTickX + mTickLength / 2 * Math.cos(thetaInRadians);
midTickY = slope * midTickX;
String sText = "" + (int) scaleRange(Math.abs(180 - i), 0, ANGLE_OFFSET_MAX, MIN_VALUE, MAX_VALUE);
canvas.drawText(sText, (float) midTickX, (float) midTickY, (mAngle <= Math.abs(181 - i)) ? mTickTextPaint : mTickTextColoredPaint);
count = 0;
} else
{
//for tick
if (tickEnable)
{
canvas.translate(mRoundTextRect.centerX(), mRoundTextRect.centerY());
thetaInRadians = Math.toRadians(180 - i);
slope = Math.tan(thetaInRadians);
startTickX = (radiusOffset * Math.cos(thetaInRadians));
startTickY = slope * startTickX;
endTickX = (startTickX + mTickLength / 2 * Math.cos(thetaInRadians));
endTickY = slope * endTickX;
canvas.drawLine((float) startTickX, (float) startTickY, (float) endTickX, (float) endTickY, (mAngle <= 359 - i) ? mTickPaint : mTickProgressPaint);
}
count++;
}
canvas.restore();
}
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
if (mTouchEnable)
{
this.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
if (ignoreTouch(event.getX(), event.getY()))
{
return false;
}
onStartTrackingTouch();
updateOnTouch(event);
break;
case MotionEvent.ACTION_MOVE:
updateOnTouch(event);
break;
case MotionEvent.ACTION_UP:
onStopTrackingTouch();
setPressed(false);
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
case MotionEvent.ACTION_CANCEL:
onStopTrackingTouch();
setPressed(false);
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
} else
{
this.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
if (ignoreTouch(event.getX(), event.getY()))
{
return false;
}
onStartTrackingTouch();
obtainOnTouchValue(event);
break;
}
}
return true;
}
private void obtainOnTouchValue(MotionEvent event)
{
mTouchAngle = getTouchDegrees(event.getX(), event.getY());
float obtainValue = (float) scaleRange(mTouchAngle, 0, ANGLE_OFFSET_MAX, MIN_VALUE, MAX_VALUE);
if (mOnProtractorViewChangeListener != null)
{
mOnProtractorViewChangeListener.onSelectedBarTouch(String.format("%.02f", obtainValue), event.getX(), event.getY());
}
}
private void onStartTrackingTouch()
{
if (mOnProtractorViewChangeListener != null)
{
mOnProtractorViewChangeListener.onStartTrackingTouch(this);
}
}
private void onStopTrackingTouch()
{
if (mOnProtractorViewChangeListener != null)
{
mOnProtractorViewChangeListener.onStopTrackingTouch(this);
}
}
private boolean ignoreTouch(float xPos, float yPos)
{
boolean ignore = false;
float x = xPos - mTranslateX;
float y = yPos - mTranslateY;
float touchRadius = (float) Math.sqrt(((x * x) + (y * y)));
if (touchRadius < mTouchIgnoreRadius || touchRadius > (mArcRadius + mTickLength + mTickOffset))
{
ignore = true;
}
return ignore;
}
private void updateOnTouch(MotionEvent event)
{
boolean ignoreTouch = ignoreTouch(event.getX(), event.getY());
if (ignoreTouch)
{
return;
}
setPressed(true);
mTouchAngle = getTouchDegrees(event.getX(), event.getY());
onProgressRefresh((int) mTouchAngle, true);
}
private double getTouchDegrees(float xPos, float yPos)
{
float x = xPos - mTranslateX;
float y = yPos - mTranslateY;
double angle = Math.toDegrees(Math.atan2(y, x) + (Math.PI));
if (angle > 270)
angle = 0;
else if (angle > 180)
angle = 180;
return angle;
}
private void onProgressRefresh(int angle, boolean fromUser)
{
updateAngle(angle, fromUser);
}
private void updateAngle(int angle, boolean fromUser)
{
mAngle = (angle > MAX) ? MAX : (angle < 0) ? 0 : angle;
this.chartvalue = (float) scaleRange(angle, 0, ANGLE_OFFSET_MAX, MIN_VALUE, MAX_VALUE);
setCenterText(String.format("%.01f", chartvalue));
if (mOnProtractorViewChangeListener != null)
{
mOnProtractorViewChangeListener.onProgressChanged(this, mAngle, fromUser);
}
invalidate();
}
/*
private void setTextSizeForWidth(Paint paint, float desiredWidth, String text, float testTextSize)
{
paint.setTextSize(testTextSize);
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
float desiredTextSize = testTextSize * desiredWidth / bounds.width();
paint.setTextSize(desiredTextSize);
}*/
public double scaleRange(final double valueIn, final double baseMin, final double baseMax, final double limitMin, final double limitMax)
{
return ((limitMax - limitMin) * (valueIn - baseMin) / (baseMax - baseMin)) + limitMin;
}
// Setters and Getters
public boolean getTouchInside()
{
return mTouchInside;
}
public boolean isTickEnable()
{
return tickEnable;
}
public void setTickEnable(boolean tickEnable)
{
this.tickEnable = tickEnable;
postInvalidate();
}
public String getCenterText()
{
return sCenterText;
}
public void setCenterText(String sCenterText)
{
this.sCenterText = sCenterText + "%";
invalidate();
}
public String convertFloatToString(float chartValue)
{
return String.format("%.02f", chartValue);
}
public void setTouchInside(boolean isEnabled)
{
mTouchInside = isEnabled;
if (mTouchInside)
{
mTouchIgnoreRadius = (float) (mArcRadius / 1.5);
}
}
public String getSubText()
{
return sSubText;
}
public void setSubText(String sSubText)
{
this.sSubText = sSubText;
invalidate();
}
public double getMIN_VALUE()
{
return MIN_VALUE;
}
public void setMIN_VALUE(double MIN_VALUE)
{
if (MAX_VALUE <= MIN_VALUE)
throw new IllegalArgumentException("Min should not be greater than max.");
this.MIN_VALUE = MIN_VALUE;
// setChartvalue(chartvalue);
invalidate();
}
public double getMAX_VALUE()
{
return MAX_VALUE;
}
public void setMAX_VALUE(double MAX_VALUE)
{
if (MAX_VALUE <= MIN_VALUE)
throw new IllegalArgumentException("Max should not be less than min.");
this.MAX_VALUE = MAX_VALUE;
// setChartvalue(chartvalue);
invalidate();
}
public boolean getProgressAnimator()
{
return animatorEnable;
}
public void setProgressAnimator(boolean animatorEnable)
{
this.animatorEnable = animatorEnable;
postInvalidate();
}
public int getCenterTextColor()
{
return iCenterTextColor;
}
public void setCenterTextColor(@ColorInt int iCenterTextColor)
{
this.iCenterTextColor = iCenterTextColor;
mCenterTextPaint.setColor(iCenterTextColor);
invalidate();
}
public int getSubTextColor()
{
return iSubTextColor;
}
public void setSubTextColor(@ColorInt int iSubTextColor)
{
this.iSubTextColor = iSubTextColor;
mSubTextPaint.setColor(iSubTextColor);
invalidate();
}
public float getChartvalue()
{
return chartvalue;
}
public void setChartvalue(float chartValue)
{
this.chartvalue = chartValue;
if (MIN_VALUE > chartValue)
this.mAngle = 0;
else if (MAX_VALUE < chartValue)
this.mAngle = ANGLE_OFFSET_MAX;
else
this.mAngle = (int) scaleRange(chartValue, MIN_VALUE, MAX_VALUE, 0, ANGLE_OFFSET_MAX);
setAngle(mAngle);
setCenterText(String.format("%.01f", chartValue));
if (progressAnimator == null && animatorEnable)
{
progressAnimator = ObjectAnimator.ofFloat(this, "chartvalue", 0, chartValue);
progressAnimator.setDuration(1000);
progressAnimator.setInterpolator(new FastOutSlowInInterpolator());
progressAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator)
{
}
@Override
public void onAnimationEnd(Animator animator)
{
progressAnimator = null;
}
@Override
public void onAnimationCancel(Animator animator)
{
}
@Override
public void onAnimationRepeat(Animator animator)
{
}
});
progressAnimator.start();
}
}
public void setOnProtractorViewChangeListener(OnProtractorViewChangeListener l)
{
mOnProtractorViewChangeListener = l;
}
public OnProtractorViewChangeListener getOnProtractorViewChangeListener()
{
return mOnProtractorViewChangeListener;
}
public int getAngle()
{
return mAngle;
}
public void setAngle(int angle)
{
this.mAngle = angle;
onProgressRefresh(mAngle, false);
}
public boolean isEnabled()
{
return mTouchEnable;
}
public void setEnabled(boolean enabled)
{
this.mTouchEnable = enabled;
invalidate();
}
public int getProgressColor()
{
return mArcProgressPaint.getColor();
}
public void setProgressColor(@ColorInt int color)
{
mArcProgressPaint.setColor(color);
invalidate();
}
public int getArcColor()
{
return mArcPaint.getColor();
}
public float getArcTextSpacing()
{
return arcTextSpacing;
}
public void setArcTextSpacing(float arcTextSpacing)
{
this.arcTextSpacing = arcTextSpacing;
postInvalidate();
}
public int getTickWidth()
{
return mTickWidth;
}
public void setTickWidth(int mTickWidth)
{
this.mTickWidth = mTickWidth;
mTickPaint.setStrokeWidth(mTickWidth);
postInvalidate();
}
public int getTickProgressWidth()
{
return mTickProgressWidth;
}
public void setTickProgressWidth(int mTickProgressWidth)
{
this.mTickProgressWidth = mTickProgressWidth;
mTickProgressPaint.setStrokeWidth(mTickProgressWidth);
postInvalidate();
}
public void setArcColor(@ColorInt int arcColor)
{
this.arcColor = arcColor;
mArcPaint.setColor(arcColor);
invalidate();
}
public int getArcProgressWidth()
{
return mArcProgressWidth;
}
public void setArcProgressWidth(int arcProgressWidth)
{
this.mArcProgressWidth = arcProgressWidth;
mArcProgressPaint.setStrokeWidth(arcProgressWidth);
invalidate();
}
public int getArcWidth()
{
return mArcWidth;
}
public void setArcWidth(int arcWidth)
{
this.mArcWidth = arcWidth;
mArcPaint.setStrokeWidth(arcWidth);
invalidate();
}
public int getArcProgressColor()
{
return arcProgressColor;
}
public void setArcProgressColor(@ColorInt int arcProgressColor)
{
this.arcProgressColor = arcProgressColor;
mArcProgressPaint.setColor(arcProgressColor);
postInvalidate();
}
public boolean isRoundedEdges()
{
return mRoundedEdges;
}
public void setRoundedEdges(boolean roundedEdges)
{
this.mRoundedEdges = roundedEdges;
if (roundedEdges)
{
mArcPaint.setStrokeCap(Paint.Cap.ROUND);
mArcProgressPaint.setStrokeCap(Paint.Cap.ROUND);
} else
{
mArcPaint.setStrokeCap(Paint.Cap.BUTT);
mArcProgressPaint.setStrokeCap(Paint.Cap.BUTT);
}
invalidate();
}
public int getTickProgressColor()
{
return tickProgressColor;
}
public void setTickProgressColor(@ColorInt int tickProgressColor)
{
this.tickProgressColor = tickProgressColor;
mTickProgressPaint.setColor(tickProgressColor);
postInvalidate();
}
public float getCenterTextSize()
{
return mCenterTextSize;
}
public void setCenterTextSize(float mCenterTextSize)
{
mCenterTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mCenterTextSize, getResources().getDisplayMetrics());
mCenterTextPaint.setTextSize(mCenterTextSize);
postInvalidate();
}
public float getSubTextSize()
{
return mSubTextSize;
}
public void setSubTextSize(float mSubTextSize)
{
mSubTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mSubTextSize, getResources().getDisplayMetrics());
mSubTextPaint.setTextSize(mSubTextSize);
postInvalidate();
}
public int getTickTextColor()
{
return tickTextColor;
}
public void setTickTextColor(@ColorInt int tickTextColor)
{
this.tickTextColor = tickTextColor;
mTickTextPaint.setColor(tickTextColor);
postInvalidate();
}
public int getTickPaintColor()
{
return tickPaintColor;
}
public void setTickPaintColor(@ColorInt int tickPaintColor)
{
this.tickPaintColor = tickPaintColor;
mTickPaint.setColor(tickPaintColor);
postInvalidate();
}
public int getTickedTextColored()
{
return tickedTextColored;
}
public void setTickedTextColored(@ColorInt int tickedTextColored)
{
this.tickedTextColored = tickedTextColored;
mTickTextColoredPaint.setColor(tickedTextColored);
postInvalidate();
}
public int getAngleTextSize()
{
return mAngleTextSize;
}
public void setAngleTextSize(int angleTextSize)
{
this.mAngleTextSize = angleTextSize;
mAngleTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mAngleTextSize, getResources().getDisplayMetrics());
mTickTextColoredPaint.setTextSize(mAngleTextSize);
mTickTextPaint.setTextSize(mAngleTextSize);
mTickPaint.setTextSize(mAngleTextSize);
invalidate();
}
public int getTickOffset()
{
return mTickOffset;
}
public void setTickOffset(int tickOffset)
{
this.mTickOffset = tickOffset;
invalidate();
}
public int getTickLength()
{
return mTickLength;
}
public void setTickLength(int tickLength)
{
this.mTickLength = tickLength;
postInvalidate();
}
public TicksBetweenLabel getTicksBetweenLabel()
{
return mTicksBetweenLabel;
}
public void setTicksBetweenLabel(TicksBetweenLabel ticksBetweenLabel)
{
this.mTicksBetweenLabel = ticksBetweenLabel;
invalidate();
}
public int getTickIntervals()
{
return mTickIntervals;
}
public void setTickIntervals(int tickIntervals)
{
this.mTickIntervals = tickIntervals;
invalidate();
}
}
@SouravKumarPandit
Copy link
Author

SouravKumarPandit commented Aug 7, 2018

HOW TO USE THIS VIEW


final CLProtractorView arcView = new CLProtractorView(this);
arcView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
arcView.setRoundedEdges(true);
arcView.setOnProtractorViewChangeListener(this);
arcView.setTickIntervals(30);//set this to zero for no value showing in arc
arcView.setRoundedEdges(false);//for round stroke or square one
arcView.setSubText("Growth Percentage");
arcView.setMIN_VALUE(0);//min value of arc
arcView.setMAX_VALUE(100);// max value of arc
arcView.setChartvalue(50);// chart value or setAngle to 90 vise versa
arcView.setArcWidth(60);// background arc width same for color
arcView.setArcProgressWidth(60);//progress arc width same for color
arcView.setSubTextSize(20);//bott om text to show info change the size according to text size
arcView.setCenterTextSize(35);//value showing text for the arc value
arcView.setRoundedEdges(true);
arcView.setTickTextColor(0xffffffff);
arcView.setTickPaintColor(0xffffffff);
arcView.setAngleTextSize(16);
arcView.setTickLength(5);
arcView.setTickOffset(0);
arcView.setTickTextColor(0xFF6BC3EC);
arcView.setTickedTextColored(0xFFFFC655);
arcView.setTickProgressColor(0xFFECE4CE);
arcView.setTickWidth(5);
arcView.setTickProgressWidth(10);
arcView.setTickEnable(true);//value showing text only
// arcView.setArcTextSpacing(10);
arcView.setTicksBetweenLabel(CLProtractorView.TicksBetweenLabel.TWO);//this is for enable the tick set to NONE for no tick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment