完成游戏详情页游戏视频基本的滚动效果,细节功能待完善 https://gitlab.ghzs.com/pm/halo-app-issues/issues/625

This commit is contained in:
chenjuntao
2019-09-25 18:29:37 +08:00
parent 6f6bffdeb7
commit 319fe2f556
30 changed files with 920 additions and 213 deletions

View File

@ -19,30 +19,30 @@ import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.ContextCompat;
public class ExpendTextView extends AppCompatTextView {
private CharSequence mSnapshotText;
private CharSequence mCloseText;
private String mExpendText = "...全文";
private int mMaxLines = 3; // 由于sdk版本限制(getMaxLines) 这里设置默认值
private boolean mInitLayout = false;
private boolean mOpenLayout = false;
private ExpandCallback mExpandCallback;
public ExpendTextView(Context context) {
super(context);
}
public ExpendTextView(Context context, AttributeSet attrs) {
super(context, attrs);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mMaxLines = getMaxLines();
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
@ -53,30 +53,30 @@ public class ExpendTextView extends AppCompatTextView {
showExpendButton();
}
}
public void setExpendText(String text) {
this.mExpendText = text;
}
public void setExpandCallback(ExpandCallback callback) {
this.mExpandCallback = callback;
}
@Override
public void setText(CharSequence text, BufferType type) {
mInitLayout = true;
super.setText(text, type);
}
private void showExpendButton() {
Layout layout = getLayout();
int start = layout.getLineStart(0);
int lastLineEnd = layout.getLineEnd(mMaxLines - 1);
int lastLineStart = layout.getLineStart(mMaxLines - 1);
float lastLineRight = layout.getLineRight(mMaxLines - 1);
int viewWidth = getWidth() - getPaddingRight() - getPaddingLeft();
TextPaint paint = getPaint();
float expendTextWidth = paint.measureText(mExpendText);
CharSequence content = mSnapshotText.subSequence(start, lastLineEnd);
@ -98,47 +98,39 @@ public class ExpendTextView extends AppCompatTextView {
int startPosition = content.length() - mExpendText.length();
startPosition = startPosition < 0 ? 0 : startPosition;
msp.replace(startPosition, length, mExpendText);
msp.setSpan(
new ClickableSpan() {
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(ContextCompat.getColor(getContext(), R.color.theme));
ds.setUnderlineText(false);
}
@Override
public void onClick(View widget) {
mOpenLayout = true;
setMaxLines(Integer.MAX_VALUE);
setText(mSnapshotText);
if (mExpandCallback != null) {
mExpandCallback.onExpand();
}
}
},
startPosition,
msp.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
msp.setSpan(
new BackgroundColorSpan(Color.WHITE),
startPosition,
msp.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
msp.setSpan(new ClickableSpan() {
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(ContextCompat.getColor(getContext(), R.color.theme));
ds.setUnderlineText(false);
}
@Override
public void onClick(View widget) {
mOpenLayout = true;
setMaxLines(Integer.MAX_VALUE);
setText(mSnapshotText);
if (mExpandCallback != null) {
mExpandCallback.onExpand();
}
}
}, startPosition, msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
msp.setSpan(new BackgroundColorSpan(Color.WHITE), startPosition, msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
setText(msp);
setMovementMethod(CustomLinkMovementMethod.getInstance());
}
public void setExpendMaxLines(int maxLines) {
mMaxLines = maxLines;
setMaxLines(maxLines);
}
public interface ExpandCallback {
void onExpand();
}
}