Usage graphs support RTL style.

Flips the canvas horizontally before drawing paths under RTL mode.

Bug: 78008951
Test: manually verified graphs of wifi data usage, app data usage, and
battery usage.

Change-Id: I79286e9f3f98632e3a9710d42c3e197231a14c39
This commit is contained in:
Leo Hsu
2018-04-20 10:40:08 +08:00
parent f817b1e3a5
commit 2e4f9fe61b
2 changed files with 7 additions and 2 deletions

View File

@@ -80,8 +80,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layoutDirection="ltr">
android:orientation="horizontal">
<include android:id="@+id/label_start"
layout="@layout/usage_side_label" />

View File

@@ -255,9 +255,15 @@ public class UsageGraph extends View {
return;
}
canvas.save();
if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
// Flip the canvas along the y-axis of the center of itself before drawing paths.
canvas.scale(-1, 1, canvas.getWidth() * 0.5f, 0);
}
drawLinePath(canvas, mLocalProjectedPaths, mDottedPaint);
drawFilledPath(canvas, mLocalPaths, mFillPaint);
drawLinePath(canvas, mLocalPaths, mLinePaint);
canvas.restore();
BatteryUtils.logRuntime(LOG_TAG, "onDraw", startTime);
}