Skip to content

Commit

Permalink
fix for issue Blogcat#2 when text takes up less line than threshold, …
Browse files Browse the repository at this point in the history
…do not show the expand button .
  • Loading branch information
vkdinventor committed Jun 24, 2017
1 parent c58061b commit 025a5fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ protected void onCreate(final Bundle savedInstanceState)
final ExpandableTextView expandableTextView = (ExpandableTextView) this.findViewById(R.id.expandableTextView);
final Button buttonToggle = (Button) this.findViewById(R.id.button_toggle);

expandableTextView.setToggleButton(buttonToggle);

// set animation duration via code, but preferable in your layout files by using the animation_duration attribute
expandableTextView.setAnimationDuration(750L);

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/lorem_ipsum.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

<string name="lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse a risus sed nulla faucibus commodo. Donec iaculis pretium facilisis. Praesent rutrum varius arcu, sed viverra ipsum malesuada id. Suspendisse nec mauris eleifend, maximus elit et, venenatis quam. Duis at maximus nisi, a congue sapien. Curabitur facilisis at nisi vitae vulputate. Phasellus vel orci et massa scelerisque ultrices. Morbi eget ipsum porttitor arcu volutpat convallis. Pellentesque velit libero, interdum sed consequat at, eleifend et nisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed convallis massa imperdiet, consectetur lectus sodales, finibus velit. Donec quis tortor vel quam porta hendrerit. Vivamus vitae consectetur orci, sed feugiat turpis.</string>

<string name="short_string">Lorem ipsum dolor sit amet, consectetur adipiscing elit. </string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.TextView;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class ExpandableTextView extends TextView
private boolean animating;
private boolean expanded;
private int collapsedHeight;
private View mToggleButton;

public ExpandableTextView(final Context context)
{
Expand Down Expand Up @@ -360,4 +362,22 @@ public interface OnExpandListener
*/
void onCollapse(ExpandableTextView view);
}

public void setToggleButton(View mToggleButton) {
this.mToggleButton = mToggleButton;
}

@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);

if (mToggleButton != null) {
if(getLineCount() >= this.maxLines){
mToggleButton.setVisibility(VISIBLE);
}else {
mToggleButton.setVisibility(GONE);
}
}
}
}

0 comments on commit 025a5fe

Please sign in to comment.