Skip to content

Commit cbd0bfd

Browse files
author
Khabibulin Renal
committed
custom thumb drawable support
1 parent d57641d commit cbd0bfd

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

supersaiyan-scrollview/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<flag name="dark" value="0"/>
1717
<flag name="light" value="1"/>
1818
</attr>
19+
<attr name="ssjn_thumbDrawable" format="reference"/>
20+
<attr name="ssjn_thumbPressedDrawable" format="reference" />
1921

2022
</declare-styleable>
2123

supersaiyan-scrollview/src/com/nolanlawson/supersaiyan/widget/SuperSaiyanScrollView.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public class SuperSaiyanScrollView extends FrameLayout
7676
private int mListOffset;
7777
private int mOverlayTextColor;
7878
private int mOverlayDrawableResId;
79+
private Drawable mThumbDrawableResource;
80+
private Drawable mThumbPressedDrawableResource;
7981

8082
private Object [] mSections;
8183
private String mSectionText;
@@ -126,6 +128,7 @@ private void useThumbDrawable(Drawable drawable) {
126128

127129
private void init(Context context, AttributeSet attrs) {
128130

131+
final Resources res = context.getResources();
129132
// set all attributes from xml
130133
if (attrs != null) {
131134
TypedArray typedArray = context.obtainStyledAttributes(attrs,
@@ -139,9 +142,12 @@ private void init(Context context, AttributeSet attrs) {
139142
mOverlayTextSize = typedArray.getDimensionPixelSize(
140143
R.styleable.SuperSaiyanScrollView_ssjn_overlayTextSize,
141144
context.getResources().getDimensionPixelSize(R.dimen.ssjn__overlay_text_size_normal));
142-
mOverlayTextColor = typedArray.getColor(R.styleable.SuperSaiyanScrollView_ssjn_overlayTextColor,
145+
mOverlayTextColor = typedArray.getColor(R.styleable.SuperSaiyanScrollView_ssjn_overlayTextColor,
143146
context.getResources().getColor(R.color.ssjn__emphasis));
144147

148+
mThumbDrawableResource = typedArray.getDrawable(R.styleable.SuperSaiyanScrollView_ssjn_thumbDrawable);
149+
mThumbPressedDrawableResource = typedArray.getDrawable(R.styleable.SuperSaiyanScrollView_ssjn_thumbPressedDrawable);
150+
145151
int overlayTheme = typedArray.getInt(R.styleable.SuperSaiyanScrollView_ssjn_overlayTheme, 1);
146152

147153
if (overlayTheme == 0) {
@@ -170,19 +176,22 @@ private void init(Context context, AttributeSet attrs) {
170176
mOverlayTextColor = context.getResources().getColor(R.color.ssjn__emphasis);
171177
mOverlayDrawableResId = R.drawable.popup_full_bright;
172178
}
179+
if (mThumbDrawableResource == null)
180+
mThumbDrawableResource = res.getDrawable(THUMB_DRAWABLE);
181+
if (mThumbPressedDrawableResource == null)
182+
mThumbPressedDrawableResource = res.getDrawable(THUMB_DRAWABLE_PRESSED);
173183

174184
log.d("Initialized with mOverlayHeight: %s, mOverlayWidth: %s, mOverlayTextSize: %s, mOverlayTextColor: %s",
175185
mOverlayHeight, mOverlayWidth, mOverlayTextSize, mOverlayTextColor);
176186

177187
// Get both the scrollbar states drawables
178-
final Resources res = context.getResources();
179188
StateListDrawable thumbDrawable = new StateListDrawable();
180189
//This for pressed true
181190
thumbDrawable.addState(STATE_PRESSED,
182-
res.getDrawable(THUMB_DRAWABLE_PRESSED));
191+
res.getDrawable(mThumbPressedDrawableResource));
183192
//This for pressed false
184193
thumbDrawable.addState(STATE_UNPRESSED,
185-
res.getDrawable(THUMB_DRAWABLE));
194+
mThumbDrawableResource);
186195
useThumbDrawable(thumbDrawable);
187196

188197
mOverlayDrawable = res.getDrawable(mOverlayDrawableResId);

0 commit comments

Comments
 (0)