Skip to content

Text overlapse overlay #17

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 2 commits 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
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>

<declare-styleable name="SuperSaiyanScrollView">
<attr name="ssjn_overlayMaxTextLength" format="integer" />
<attr name="ssjn_overlayWidth" format="dimension" />
<attr name="ssjn_overlayHeight" format="dimension" />
<attr name="ssjn_overlayTextSize" format="dimension" />
Expand All @@ -16,6 +17,7 @@
<flag name="dark" value="0"/>
<flag name="light" value="1"/>
</attr>


</declare-styleable>

Expand Down
12 changes: 10 additions & 2 deletions supersaiyan-scrollview/src/com/nolanlawson/supersaiyan/widget/SuperSaiyanScrollView.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class SuperSaiyanScrollView extends FrameLayout
private int mOverlayWidth;
private int mOverlayHeight;
private float mOverlayTextSize;
private int mOverlayMaxTextLength;

private boolean mDragging;
private ListView mList;
Expand Down Expand Up @@ -161,6 +162,8 @@ private void init(Context context, AttributeSet attrs) {
mOverlayWidth = getContext().getResources().getDimensionPixelSize(scheme.getWidth());
}

mOverlayMaxTextLength = typedArray.getInteger(R.styleable.SuperSaiyanScrollView_ssjn_overlayMaxTextLength,-1);

typedArray.recycle();
} else {
// no attrs, so initialize with defaults
Expand Down Expand Up @@ -444,7 +447,12 @@ private void scrollTo(float position) {
}

if (sectionIndex >= 0) {
String text = mSectionText = sections[sectionIndex].toString();
String sectionName = sections[sectionIndex].toString();
if(-1 < mOverlayMaxTextLength) {
sectionName = sectionName.substring(0, Math.min(mOverlayMaxTextLength, sectionName.length()));
sectionName = sectionName.length() == mOverlayMaxTextLength ? sectionName + "..." : sectionName;
}
String text = mSectionText =sectionName;
mDrawOverlay = (text.length() != 1 || text.charAt(0) != ' ') &&
sectionIndex < sections.length;
} else {
Expand Down Expand Up @@ -580,4 +588,4 @@ public void setOverlaySizeScheme(OverlaySizeScheme scheme) {
mOverlayWidth = getContext().getResources().getDimensionPixelSize(scheme.getWidth());
updateOverlaySize(mLastW, mLastH, mLastOldw, mLastOldh);
}
}
}