Skip to content
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

fix: totals cell wrapping #173

Merged
merged 3 commits into from Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.GestureDetector;
import android.view.MenuItem;
import android.view.MotionEvent;
Expand Down Expand Up @@ -76,6 +77,7 @@ private void createContent(String type, DataColumn dataColumn) {
case "text":
ClickableTextView textView = new ClickableTextView(getContext(), selectionsEngine, tableView, this, dataColumn);
textView.setPadding(PADDING, 0, PADDING, 0);
textView.setEllipsize(TextUtils.TruncateAt.END);
content = textView;
break;
case "image":
Expand Down Expand Up @@ -209,16 +211,21 @@ public void onRecycled() {
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) getLayoutParams();
if(column == null) {
return;
}
layout.width = column.width;
setLayoutParams(layout);
public void requestLayout() {
super.requestLayout();
post(measureAndLayout);
}

private final Runnable measureAndLayout = new Runnable() {
@Override
public void run() {
measure(
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
layout(getLeft(), getTop(), getRight(), getBottom());
}
};

class SingleTapListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
Expand Down
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.graphics.Paint;
import android.graphics.Rect;
Expand Down Expand Up @@ -217,9 +218,8 @@ public boolean isSelected(){
return selected;
}

@Override
public void setMaxLines(int maxLines) {
maxLines = textWrapper.setMaxLines(maxLines);
public void setMaxLines(int maxLines, DataColumn column) {
maxLines = textWrapper.setMaxLines(maxLines, column);
super.setMaxLines(maxLines);
}

Expand All @@ -230,6 +230,9 @@ public void testTextWrap(DataColumn dataColumn) {
}

public int getMeasuredLineCount() {
if(column != null && !column.isDim) {
return 1;
}
return textWrapper.getMeasuredLinedCount();
}

Expand All @@ -247,4 +250,5 @@ public void copyToClipBoard() {
public String getCopyMenuString() {
return "copy";
}

}
Expand Up @@ -120,8 +120,8 @@ public boolean onTouchEvent(@NonNull MotionEvent e) {
}

void setMaxLines(int maxLineCount) {
if(this.cell != null) {
this.cell.setMaxLines(maxLineCount);
if(this.cell != null && this.column != null) {
this.cell.setMaxLines(maxLineCount, this.column);
}
}
@SuppressLint("ViewConstructor")
Expand Down Expand Up @@ -149,9 +149,8 @@ public void testTextWrap() {
}
}

@Override
public void setMaxLines(int maxLines) {
maxLines = textWrapper.setMaxLines(maxLines);
public void setMaxLines(int maxLines, DataColumn column) {
maxLines = textWrapper.setMaxLines(maxLines, column);
super.setMaxLines(maxLines);
}

Expand Down
Expand Up @@ -54,7 +54,7 @@ public int getMaxLineCount() {

for(int i = 0; i < this.dataColumns.size(); i++) {
HeaderCell headerCell = (HeaderCell)this.getChildAt(i);
headerCell.cell.setMaxLines(lineCount);
headerCell.cell.setMaxLines(lineCount, dataColumns.get(i));
}
return lineCount;
}
Expand Down
Expand Up @@ -98,7 +98,7 @@ public void setData(DataRow dataRow, int rowHeight, CellContentStyle cellContent
setupHyperLink(textView);
}
if(column.isDim && cellContentStyle.wrap) {
textView.setMaxLines(rowHeight/cellContentStyle.lineHeight);
textView.setMaxLines(rowHeight/cellContentStyle.lineHeight, column);
} else {
textView.setMaxLines(1);
}
Expand Down Expand Up @@ -149,18 +149,9 @@ public boolean updateWidth(float deltaWidth, int column) {

DataColumn dataColumn = dataProvider.dataColumns.get(column);
checkTextWrap(dataColumn);
checkNeighbourTextWrap(column);

return true;
}

private void checkNeighbourTextWrap(int column) {
if (column + 1 < numColumns ) {
DataColumn dataColumn = dataProvider.dataColumns.get(column);
checkTextWrap(dataColumn);
}
}

private void checkTextWrap(DataColumn dataColumn) {
if(dataColumn.isDim && dataColumn.isText() ) {
CellView cellView = (CellView) row.getChildAt(dataColumn.columnIndex);
Expand Down Expand Up @@ -233,7 +224,7 @@ public void initializeHeight(int rowHeight, CellContentStyle cellContentStyle) {
if(column.columnIndex < row.getChildCount()) {
CellView cellView = (CellView) row.getChildAt(column.columnIndex);
ClickableTextView clickableTextView = (ClickableTextView) cellView.content;
clickableTextView.setMaxLines(lines);
clickableTextView.setMaxLines(lines, column);
clickableTextView.setGravity(column.textAlignment | Gravity.CENTER_VERTICAL);
clickableTextView.requestLayout();
}
Expand Down
Expand Up @@ -65,7 +65,7 @@ void measureLineCountNoUpdate() {
}

protected int calculateLineCount() {
int width = column.width - additionalPadding;
int width = Math.max(column.width - textView.getPaddingRight() - textView.getPaddingLeft(), 0);
measureTextPaint.setTypeface(textView.getTypeface());
StaticLayout.Builder builder = StaticLayout.Builder.obtain(textView.getText(), 0, textView.getText().length(), measureTextPaint, width);
builder.setIncludePad(true);
Expand All @@ -81,10 +81,16 @@ public int getMeasuredLinedCount() {
return lineCount;
}

public int setMaxLines(int maxLines) {
countWords(textView.getText().toString());
maxLines = wordCount > 1 ? maxLines : 1;
public int setMaxLines(int maxLines, DataColumn column) {
if(column.isDim) {
countWords(textView.getText().toString());
maxLines = wordCount > 1 ? maxLines : 1;
} else {
maxLines = 1;
wordCount = 1;
}
return maxLines;

}

public void countWords(String text) {
Expand Down
Expand Up @@ -48,7 +48,7 @@ public int getMaxLineCount() {

for(int i = 0; i < this.dataColumns.size(); i++) {
TotalsViewCell totalsCell = (TotalsViewCell)this.getChildAt(i);
totalsCell.setMaxLines(lineCount);
totalsCell.setMaxLines(lineCount, dataColumns.get(i));
}
return lineCount;
}
Expand Down
Expand Up @@ -36,13 +36,15 @@ public void testTextWrap() {
}
}

@Override
public void setMaxLines(int maxLines) {
maxLines = textWrapper.setMaxLines(maxLines);
public void setMaxLines(int maxLines, DataColumn column) {
maxLines = textWrapper.setMaxLines(maxLines, column);
super.setMaxLines(maxLines);
}

int getMeasuredLinedCount() {
if(column != null && !column.isDim) {
return 1;
}
return textWrapper.getMeasuredLinedCount();
}

Expand Down