Skip to content

Commit 13c0351

Browse files
committed
added stroke
1 parent 2d7492e commit 13c0351

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

alphabetsindexfastscrollrecycler/src/main/java/in/myinnos/alphabetsindexfastscrollrecycler/IndexFastScrollRecyclerSection.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public class IndexFastScrollRecyclerSection extends RecyclerView.AdapterDataObse
4444
private Typeface setTypeface = null;
4545
private Boolean setIndexBarVisibility = true;
4646
private Boolean setSetIndexBarHighLateTextVisibility = false;
47+
private Boolean setIndexBarStrokeVisibility = true;
48+
public int mIndexBarStrokeWidth = 2;
49+
private @ColorInt
50+
int mIndexBarStrokeColor;
4751
private @ColorInt
4852
int indexbarBackgroudColor;
4953
private @ColorInt
@@ -73,6 +77,9 @@ public IndexFastScrollRecyclerSection(Context context, IndexFastScrollRecyclerVi
7377
previewTextColor = recyclerView.mPreviewTextColor;
7478
previewBackgroudAlpha = convertTransparentValueToBackgroundAlpha(recyclerView.mPreviewTransparentValue);
7579

80+
mIndexBarStrokeColor = recyclerView.mSetIndexBarStrokeColor;
81+
mIndexBarStrokeWidth = recyclerView.mIndexBarStrokeWidth;
82+
7683
setIndexBarCornerRadius = recyclerView.mIndexBarCornerRadius;
7784
indexbarBackgroudColor = recyclerView.mIndexbarBackgroudColor;
7885
indexbarTextColor = recyclerView.mIndexbarTextColor;
@@ -95,11 +102,19 @@ public void draw(Canvas canvas) {
95102
if (setIndexBarVisibility) {
96103

97104
Paint indexbarPaint = new Paint();
105+
98106
indexbarPaint.setColor(indexbarBackgroudColor);
99107
indexbarPaint.setAlpha(indexbarBackgroudAlpha);
100108
indexbarPaint.setAntiAlias(true);
101109
canvas.drawRoundRect(mIndexbarRect, setIndexBarCornerRadius * mDensity, setIndexBarCornerRadius * mDensity, indexbarPaint);
102110

111+
if (setIndexBarStrokeVisibility) {
112+
indexbarPaint.setStyle(Paint.Style.STROKE);
113+
indexbarPaint.setColor(mIndexBarStrokeColor);
114+
indexbarPaint.setStrokeWidth(mIndexBarStrokeWidth); // set stroke width
115+
canvas.drawRoundRect(mIndexbarRect, setIndexBarCornerRadius * mDensity, setIndexBarCornerRadius * mDensity, indexbarPaint);
116+
}
117+
103118
if (mSections != null && mSections.length > 0) {
104119
// Preview is shown when mCurrentSection is set
105120
if (previewVisibility && mCurrentSection >= 0 && mSections[mCurrentSection] != "") {
@@ -334,13 +349,29 @@ public void setIndexBarVisibility(boolean shown) {
334349
setIndexBarVisibility = shown;
335350
}
336351

352+
353+
/**
354+
* @param shown boolean to show or hide the index bar
355+
*/
356+
public void setIndexBarStrokeVisibility(boolean shown) {
357+
setIndexBarStrokeVisibility = shown;
358+
}
359+
337360
/**
338361
* @param shown boolean to show or hide the preview box
339362
*/
340363
public void setPreviewVisibility(boolean shown) {
341364
previewVisibility = shown;
342365
}
343366

367+
/**
368+
* @param value int to set the text size of the preview box
369+
*/
370+
public void setIndexBarStrokeWidth(int value) {
371+
mIndexBarStrokeWidth = value;
372+
}
373+
374+
344375
/**
345376
* @param value int to set the text size of the preview box
346377
*/
@@ -383,6 +414,14 @@ public void setIndexBarTextColor(@ColorInt int color) {
383414
indexbarTextColor = color;
384415
}
385416

417+
/**
418+
* @param color The text color for the index bar
419+
*/
420+
public void setIndexBarStrokeColor(@ColorInt int color) {
421+
mIndexBarStrokeColor = color;
422+
}
423+
424+
386425
/**
387426
* @param color The text color for the index bar
388427
*/

alphabetsindexfastscrollrecycler/src/main/java/in/myinnos/alphabetsindexfastscrollrecycler/IndexFastScrollRecyclerView.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import androidx.annotation.ColorInt;
1414
import androidx.annotation.ColorRes;
1515
import androidx.recyclerview.widget.RecyclerView;
16+
1617
import android.util.AttributeSet;
1718
import android.view.GestureDetector;
1819
import android.view.MotionEvent;
@@ -30,6 +31,9 @@ public class IndexFastScrollRecyclerView extends RecyclerView {
3031
public int mPreviewPadding = 5;
3132
public int mIndexBarCornerRadius = 5;
3233
public float mIndexBarTransparentValue = (float) 0.6;
34+
public int mIndexBarStrokeWidth = 2;
35+
public @ColorInt
36+
int mSetIndexBarStrokeColor = Color.BLACK;
3337
public @ColorInt
3438
int mIndexbarBackgroudColor = Color.BLACK;
3539
public @ColorInt
@@ -108,7 +112,15 @@ private void init(Context context, AttributeSet attrs) {
108112
if (typedArray.hasValue(R.styleable.IndexFastScrollRecyclerView_setPreviewTextColor)) {
109113
mPreviewTextColor = Color.parseColor(typedArray.getString(R.styleable.IndexFastScrollRecyclerView_setPreviewTextColor));
110114
}
111-
115+
116+
if (typedArray.hasValue(R.styleable.IndexFastScrollRecyclerView_setIndexBarStrokeWidth)) {
117+
mIndexBarStrokeWidth = typedArray.getInt(R.styleable.IndexFastScrollRecyclerView_setIndexBarStrokeWidth, mIndexBarStrokeWidth);
118+
}
119+
120+
if (typedArray.hasValue(R.styleable.IndexFastScrollRecyclerView_setIndexBarStrokeColor)) {
121+
mSetIndexBarStrokeColor = Color.parseColor(typedArray.getString(R.styleable.IndexFastScrollRecyclerView_setIndexBarStrokeColor));
122+
}
123+
112124
} finally {
113125
typedArray.recycle();
114126
}
@@ -228,6 +240,28 @@ public void setIndexBarVisibility(boolean shown) {
228240
mEnabled = shown;
229241
}
230242

243+
/**
244+
* @param shown boolean to show or hide the index bar
245+
*/
246+
public void setIndexBarStrokeVisibility(boolean shown) {
247+
mScroller.setIndexBarStrokeVisibility(shown);
248+
}
249+
250+
/**
251+
* @param color The color for the index bar
252+
*/
253+
public void setIndexBarStrokeColor(String color) {
254+
mScroller.setIndexBarStrokeColor(Color.parseColor(color));
255+
}
256+
257+
/**
258+
* @param value int to set the text size of the preview box
259+
*/
260+
public void setIndexBarStrokeWidth(int value) {
261+
mScroller.setIndexBarStrokeWidth(value);
262+
}
263+
264+
231265
/**
232266
* @param shown boolean to show or hide the preview
233267
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<attr name="setIndexBarColorRes" format="color" />
1818
<attr name="setIndexBarTextColorRes" format="color" />
1919
<attr name="setIndexBarHighlightTextColorRes" format="color" />
20+
<attr name="setIndexBarStrokeWidth" format="integer" />
21+
<attr name="setIndexBarStrokeColor" format="color" />
2022
</declare-styleable>
2123
</resources>

app/src/main/java/in/myinnos/indexfastscrollrecycler/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ protected void initialiseUI() {
8282
mRecyclerView.setPreviewTransparentValue(0.6f);
8383

8484
mRecyclerView.setIndexBarVisibility(true);
85+
86+
mRecyclerView.setIndexBarStrokeVisibility(true);
87+
mRecyclerView.setIndexBarStrokeWidth(1);
88+
mRecyclerView.setIndexBarStrokeColor("#000000");
89+
8590
mRecyclerView.setIndexbarHighlightTextColor("#33334c");
8691
mRecyclerView.setIndexBarHighLateTextVisibility(true);
8792

0 commit comments

Comments
 (0)