Make Settings PercentageBar RTL aware

- see bug #5429822 UI should be mirrored for RTL locales (Arabic, Hebrew, farsi)

Change-Id: I7c4c4207650fa4442f6eb20f2195101e23b1b0b2
This commit is contained in:
Fabrice Di Meglio
2012-07-24 17:31:22 -07:00
parent 24d1058d00
commit a82d9a8d37

View File

@@ -71,29 +71,56 @@ public class PercentageBarChart extends View {
final int width = right - left; final int width = right - left;
float lastX = left; final boolean isLayoutRtl = isLayoutRtl();
if (isLayoutRtl) {
float nextX = right;
if (mEntries != null) { if (mEntries != null) {
for (final Entry e : mEntries) { for (final Entry e : mEntries) {
final float entryWidth; final float entryWidth;
if (e.percentage == 0.0f) { if (e.percentage == 0.0f) {
entryWidth = 0.0f; entryWidth = 0.0f;
} else { } else {
entryWidth = Math.max(mMinTickWidth, width * e.percentage); entryWidth = Math.max(mMinTickWidth, width * e.percentage);
}
final float lastX = nextX - entryWidth;
if (lastX < left) {
canvas.drawRect(left, top, nextX, bottom, e.paint);
return;
}
canvas.drawRect(lastX, top, nextX, bottom, e.paint);
nextX = lastX;
} }
final float nextX = lastX + entryWidth;
if (nextX > right) {
canvas.drawRect(lastX, top, right, bottom, e.paint);
return;
}
canvas.drawRect(lastX, top, nextX, bottom, e.paint);
lastX = nextX;
} }
}
canvas.drawRect(lastX, top, right, bottom, mEmptyPaint); canvas.drawRect(left, top, nextX, bottom, mEmptyPaint);
} else {
float lastX = left;
if (mEntries != null) {
for (final Entry e : mEntries) {
final float entryWidth;
if (e.percentage == 0.0f) {
entryWidth = 0.0f;
} else {
entryWidth = Math.max(mMinTickWidth, width * e.percentage);
}
final float nextX = lastX + entryWidth;
if (nextX > right) {
canvas.drawRect(lastX, top, right, bottom, e.paint);
return;
}
canvas.drawRect(lastX, top, nextX, bottom, e.paint);
lastX = nextX;
}
}
canvas.drawRect(lastX, top, right, bottom, mEmptyPaint);
}
} }
/** /**