use DIPs for ArrowedText

This commit is contained in:
Adrian Ulrich 2020-01-19 13:00:13 +01:00
parent ebad3392ff
commit 3928e7dbcf
2 changed files with 37 additions and 16 deletions

View File

@ -523,16 +523,14 @@ public class LibraryActivity
colors[1] = tmp;
}
int rightPadding = 2;
if (last) {
colors[1] = 0xFF404040;
rightPadding = 0;
view.setOnClickListener(this);
}
int leftPadding = 14;
if (first) {
leftPadding = 4;
leftPadding = 6;
colors[0] = colors[1];
}
@ -541,22 +539,23 @@ public class LibraryActivity
view.setText(txt);
view.setTextColor(Color.WHITE);
view.setLayoutParams(params);
view.setPadding(leftPadding, 6, rightPadding, 6);
view.setArrowWidth(arrowWidth);
view.setPaddingDIP(leftPadding, 2, 6, 2);
view.setArrowWidthDIP(arrowWidth);
view.setTag(i);
view.setColors(colors[0], colors[1]);
mLimiterViews.addView(view);
if (last) {
final int ap = 10;
ArrowedText end = new ArrowedText(this);
end.setOnClickListener(this);
end.setText("×");
end.setTextColor(0xFFB0B0B0);
end.setLayoutParams(params);
end.setPadding(6, 6, 0, 6);
end.setArrowPadding(14);
end.setArrowWidth(arrowWidth);
end.setMinWidth(arrowWidth+14);
end.setPaddingDIP(0, 2, 0, 2);
end.setArrowWidthDIP(arrowWidth);
end.setArrowPaddingDIP(ap);
end.setMinWidthDIP(arrowWidth+ap);
end.setTag(i);
end.setColors(colors[1], 0);
mLimiterViews.addView(end);

View File

@ -34,36 +34,58 @@ public class ArrowedText extends TextView {
* Context this view uses.
*/
Context mContext;
/**
* Display density of the device.
*/
float mDensity;
/**
* Color of the arrow on the left side.
*/
int mArrowColor;
/**
* Controls the width of the drawn arrow.
* Controls the width of the drawn arrow in DIP.
*/
float mArrowWidth;
/**
* 'padding' space (used left side) for the arrow to consume.
* 'padding' space (used left side) for the arrow to consume in DIP.
*/
int mArrowPadding;
float mArrowPadding;
public ArrowedText(Context context) {
super(context);
mContext = context;
mDensity = context.getResources().getDisplayMetrics().density;
}
/**
* Configures the width of the arrow.
*/
public void setArrowWidth(int w) {
mArrowWidth = w;
public void setArrowWidthDIP(float w) {
mArrowWidth = w * mDensity;
}
/**
* Configures how much space the arrow uses on the left side.
*/
public void setArrowPadding(int p) {
mArrowPadding = p;
public void setArrowPaddingDIP(float p) {
mArrowPadding = p * mDensity;
}
/**
* Configures the padding of this view in DIP.
*/
public void setPaddingDIP(float left, float top, float right, float bottom) {
setPadding((int)(left*mDensity),
(int)(top*mDensity),
(int)(right*mDensity),
(int)(bottom*mDensity));
}
/**
* Configures the minimal width of this view in DIP.
*/
public void setMinWidthDIP(float w) {
setMinWidth((int)(w*mDensity));
}
/**