Skip to content

custom thumb drawable support #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions supersaiyan-scrollview/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<flag name="dark" value="0"/>
<flag name="light" value="1"/>
</attr>
<attr name="ssjn_thumbDrawable" format="reference"/>
<attr name="ssjn_thumbPressedDrawable" format="reference" />

</declare-styleable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class SuperSaiyanScrollView extends FrameLayout
private int mListOffset;
private int mOverlayTextColor;
private int mOverlayDrawableResId;
private Drawable mThumbDrawableResource;
private Drawable mThumbPressedDrawableResource;

private Object [] mSections;
private String mSectionText;
Expand Down Expand Up @@ -126,6 +128,7 @@ private void useThumbDrawable(Drawable drawable) {

private void init(Context context, AttributeSet attrs) {

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

mThumbDrawableResource = typedArray.getDrawable(R.styleable.SuperSaiyanScrollView_ssjn_thumbDrawable);
mThumbPressedDrawableResource = typedArray.getDrawable(R.styleable.SuperSaiyanScrollView_ssjn_thumbPressedDrawable);

int overlayTheme = typedArray.getInt(R.styleable.SuperSaiyanScrollView_ssjn_overlayTheme, 1);

if (overlayTheme == 0) {
Expand Down Expand Up @@ -170,19 +176,22 @@ private void init(Context context, AttributeSet attrs) {
mOverlayTextColor = context.getResources().getColor(R.color.ssjn__emphasis);
mOverlayDrawableResId = R.drawable.popup_full_bright;
}
if (mThumbDrawableResource == null)
mThumbDrawableResource = res.getDrawable(THUMB_DRAWABLE);
if (mThumbPressedDrawableResource == null)
mThumbPressedDrawableResource = res.getDrawable(THUMB_DRAWABLE_PRESSED);

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

// Get both the scrollbar states drawables
final Resources res = context.getResources();
StateListDrawable thumbDrawable = new StateListDrawable();
//This for pressed true
thumbDrawable.addState(STATE_PRESSED,
res.getDrawable(THUMB_DRAWABLE_PRESSED));
res.getDrawable(mThumbPressedDrawableResource));
//This for pressed false
thumbDrawable.addState(STATE_UNPRESSED,
res.getDrawable(THUMB_DRAWABLE));
mThumbDrawableResource);
useThumbDrawable(thumbDrawable);

mOverlayDrawable = res.getDrawable(mOverlayDrawableResId);
Expand Down