diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 1909006..8322e00 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -6,7 +6,7 @@
android:layout_height="match_parent"
tools:context=".MainActivity">
-
diff --git a/ratingtrendlib/src/main/java/com/ritwik/ratingtrendlib/Rating.java b/ratingtrendlib/src/main/java/com/ritwik/ratingtrendlib/Rating.java
index 6f9e427..9baee04 100644
--- a/ratingtrendlib/src/main/java/com/ritwik/ratingtrendlib/Rating.java
+++ b/ratingtrendlib/src/main/java/com/ritwik/ratingtrendlib/Rating.java
@@ -1,147 +1,26 @@
package com.ritwik.ratingtrendlib;
import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.RectF;
-import android.util.AttributeSet;
-import android.view.View;
-import androidx.annotation.Nullable;
+public class Rating {
-public class Rating extends View {
- /*Default values*/
- private static final float DEFAULT_STROKE_WIDTH = 4f;
- private static final float DEFAULT_FONT_SIZE = 4f;
+ private int mValue;
+ private int mStrokeColor;
+ private int mFillColor;
+ private Context mContext;
- private static final int DEFAULT_STROKE_COLOR = 0xFF305D02;
- private static final int DEFAULT_RATE_VALUE = 5;
- private static final float DEFAULT_CORNER_RADIUS = 2f;
+ public Rating(int value) {
+ this.mValue = value;
- /***
- * User defined values
- */
- private int mWidth;
- private int mHeight;
-
- private Paint mStrokePaint;
- private Paint mFillPaint;
- private int mRateValue = DEFAULT_RATE_VALUE;
- private float mStrokeWidth = DEFAULT_STROKE_WIDTH;
- private int mStrokeColor = DEFAULT_STROKE_COLOR;
- private int mFillColor = DEFAULT_STROKE_COLOR;
- private float mFontSize = DEFAULT_FONT_SIZE;
- private float mCornerRadius = DEFAULT_CORNER_RADIUS;
-
-
-
- public Rating(Context context) {
- this(context, null);
- }
-
- public Rating(Context context, @Nullable AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public Rating(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- initPaints();
- }
-
- /***
- * Initializing user defined values
- *
- * @param context :
- * @param attrs :
- */
- private void initAttrs(Context context, AttributeSet attrs){
-
- }
-
- public void initPaints(){
-
-
- mFillPaint = new Paint();
- mFillPaint.setColor(getResources().getColor(R.color.red));
- mFillPaint.setAntiAlias(true);
- mFillPaint.setStyle(Paint.Style.FILL);
-
- mStrokePaint = new Paint();
- mStrokePaint.setAntiAlias(true);
- mStrokePaint.setStyle(Paint.Style.STROKE);
- mStrokePaint.setColor(mStrokeColor);
- mStrokePaint.setStrokeWidth(mStrokeWidth);
-
- }
-
- private int getDefaultWidth(){
-
- return 20;
- }
- private int getDefaultHeight(){
- return 20;
}
- private int getExpectSize(int size, int measureSpec){
+ private int getAppropriateStrokeColor(int value){
+ int color = 0xff000000;
+ switch (value){
- int result = size;
- int specMode = MeasureSpec.getMode(measureSpec);
- int specSize = MeasureSpec.getSize(measureSpec);
-
- switch (specMode) {
- case MeasureSpec.EXACTLY:
- result = specSize;
- break;
- case MeasureSpec.UNSPECIFIED:
- result = size;
- break;
- case MeasureSpec.AT_MOST:
- result = Math.min(size, specSize);
- break;
- default:
- break;
}
- return result;
-
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int defWidth = getDefaultWidth();
- int defHeight = getDefaultHeight();
- setMeasuredDimension(getExpectSize(defWidth, widthMeasureSpec),
- getExpectSize(defHeight, heightMeasureSpec));
- }
-
- /***
- * @deprecated {@link #DEFAULT_FONT_SIZE}
- * @param canvas
- */
-
- @Override
- protected void onDraw(Canvas canvas) {
-
- super.onDraw(canvas);
-
- float left = mStrokeWidth * 0.5f;
- float top = mStrokeWidth * 0.5f;
- float right = getWidth() - mStrokeWidth * 0.5f;
- float bottom = getHeight() - mStrokeWidth * 0.5f;
-
- canvas.drawRoundRect(new RectF(left, top, right, bottom),
- 20, 20, mStrokePaint);
-
-
-
- }
-
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- mWidth = getMeasuredWidth();
- mHeight = getMeasuredHeight();
+ return color;
}
}
diff --git a/ratingtrendlib/src/main/java/com/ritwik/ratingtrendlib/RatingTrendView.java b/ratingtrendlib/src/main/java/com/ritwik/ratingtrendlib/RatingTrendView.java
new file mode 100644
index 0000000..3903e0b
--- /dev/null
+++ b/ratingtrendlib/src/main/java/com/ritwik/ratingtrendlib/RatingTrendView.java
@@ -0,0 +1,149 @@
+package com.ritwik.ratingtrendlib;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.util.AttributeSet;
+import android.view.View;
+
+import androidx.annotation.Nullable;
+
+public class RatingTrendView extends View {
+ /*Default values*/
+ private static final float DEFAULT_STROKE_WIDTH = 4f;
+ private static final float DEFAULT_FONT_SIZE = 4f;
+
+ private static final int DEFAULT_STROKE_COLOR = 0xFF305D02;
+ private static final int DEFAULT_RATE_VALUE = 5;
+ private static final float DEFAULT_CORNER_RADIUS = 2f;
+
+
+
+ /***
+ * User defined values
+ */
+ private int mWidth;
+ private int mHeight;
+
+ private int[] mRatingSequence;
+
+
+ private Paint mStrokePaint;
+ private Paint mFillPaint;
+ private float mStrokeWidth = DEFAULT_STROKE_WIDTH;
+ private int mStrokeColor = DEFAULT_STROKE_COLOR;
+ private int mFillColor = DEFAULT_STROKE_COLOR;
+ private float mFontSize = DEFAULT_FONT_SIZE;
+ private float mCornerRadius = DEFAULT_CORNER_RADIUS;
+
+
+
+ public RatingTrendView(Context context) {
+ this(context, null);
+ }
+
+ public RatingTrendView(Context context, @Nullable AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ //Focus on this constructor
+ public RatingTrendView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ initAttrs(context, attrs);
+ initPaints();
+ }
+
+ /***
+ * Initializing user defined values
+ *
+ * @param context :
+ * @param attrs :
+ */
+ private void initAttrs(Context context, AttributeSet attrs){
+
+ }
+
+ public void initPaints(){
+
+
+ mFillPaint = new Paint();
+ mFillPaint.setAntiAlias(true);
+ mFillPaint.setStyle(Paint.Style.FILL);
+
+ mStrokePaint = new Paint();
+ mStrokePaint.setAntiAlias(true);
+ mStrokePaint.setStyle(Paint.Style.STROKE);
+ mStrokePaint.setColor(mStrokeColor);
+ mStrokePaint.setStrokeWidth(mStrokeWidth);
+
+ }
+
+ private int getDefaultWidth(){
+
+ return 20;
+ }
+ private int getDefaultHeight(){
+ return 20;
+ }
+
+ private int getExpectSize(int size, int measureSpec){
+
+ int result = size;
+ int specMode = MeasureSpec.getMode(measureSpec);
+ int specSize = MeasureSpec.getSize(measureSpec);
+
+ switch (specMode) {
+ case MeasureSpec.EXACTLY:
+ result = specSize;
+ break;
+ case MeasureSpec.UNSPECIFIED:
+ result = size;
+ break;
+ case MeasureSpec.AT_MOST:
+ result = Math.min(size, specSize);
+ break;
+ default:
+ break;
+ }
+ return result;
+
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int defWidth = getDefaultWidth();
+ int defHeight = getDefaultHeight();
+ setMeasuredDimension(getExpectSize(defWidth, widthMeasureSpec),
+ getExpectSize(defHeight, heightMeasureSpec));
+ }
+
+ /***
+ * @deprecated {@link #DEFAULT_FONT_SIZE}
+ * @param canvas
+ */
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+
+ super.onDraw(canvas);
+
+ float left = mStrokeWidth * 0.5f;
+ float top = mStrokeWidth * 0.5f;
+ float right = getWidth() - mStrokeWidth * 0.5f;
+ float bottom = getHeight() - mStrokeWidth * 0.5f;
+
+ canvas.drawRoundRect(new RectF(left, top, right, bottom),
+ 20, 20, mStrokePaint);
+
+
+
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ mWidth = getMeasuredWidth();
+ mHeight = getMeasuredHeight();
+ }
+}
diff --git a/ratingtrendlib/src/main/res/values/attrs.xml b/ratingtrendlib/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..fe17d31
--- /dev/null
+++ b/ratingtrendlib/src/main/res/values/attrs.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ratingtrendlib/src/main/res/values/colors.xml b/ratingtrendlib/src/main/res/values/colors.xml
index cdaa286..1bec97d 100644
--- a/ratingtrendlib/src/main/res/values/colors.xml
+++ b/ratingtrendlib/src/main/res/values/colors.xml
@@ -1,4 +1,5 @@
- #ff0000
+ #ff0000
+ #ffff00
\ No newline at end of file