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

View File

@ -34,36 +34,58 @@ public class ArrowedText extends TextView {
* Context this view uses. * Context this view uses.
*/ */
Context mContext; Context mContext;
/**
* Display density of the device.
*/
float mDensity;
/** /**
* Color of the arrow on the left side. * Color of the arrow on the left side.
*/ */
int mArrowColor; int mArrowColor;
/** /**
* Controls the width of the drawn arrow. * Controls the width of the drawn arrow in DIP.
*/ */
float mArrowWidth; 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) { public ArrowedText(Context context) {
super(context); super(context);
mContext = context; mContext = context;
mDensity = context.getResources().getDisplayMetrics().density;
} }
/** /**
* Configures the width of the arrow. * Configures the width of the arrow.
*/ */
public void setArrowWidth(int w) { public void setArrowWidthDIP(float w) {
mArrowWidth = w; mArrowWidth = w * mDensity;
} }
/** /**
* Configures how much space the arrow uses on the left side. * Configures how much space the arrow uses on the left side.
*/ */
public void setArrowPadding(int p) { public void setArrowPaddingDIP(float p) {
mArrowPadding = 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));
} }
/** /**