The widget layout that was used resulted in a clipped usage bar.
It also had a 6dip left offset inherited from the default layout
which adds margin after the text (even if the text is empty here).
Used a custom layout for the whole preference to fix this issue.
Other fixes in the drawing code to prevent accumulative rounding
issues.
Change-Id: Ief9bf85260345355615c9670624d86f0893eb2d2
See the License for the specific language governing permissions and
limitations under the License.
-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical"
+ android:paddingRight="?android:attr/scrollbarSize"
+ android:paddingLeft="@*android:dimen/preference_widget_width">
-<com.android.settings.deviceinfo.PercentageBarChart
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+ <com.android.settings.deviceinfo.PercentageBarChart
+ android:id="@+id/percentage_bar_chart"
android:layout_width="match_parent"
android:layout_height="32dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
- android:id="@+id/percentage_bar_chart"
- android:paddingRight="?android:attr/scrollbarSize"
settings:minTickWidth="6dip"
settings:emptyColor="@color/memory_avail">
+ </com.android.settings.deviceinfo.PercentageBarChart>
-</com.android.settings.deviceinfo.PercentageBarChart>
+</LinearLayout>
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.DialogInterface.OnCancelListener;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.graphics.drawable.ShapeDrawable;
final int width = right - left;
- int lastX = left;
+ float lastX = left;
if (mEntries != null) {
for (final Entry e : mEntries) {
- final int entryWidth;
- if (e.percentage == 0f) {
- entryWidth = 0;
+ final float entryWidth;
+ if (e.percentage == 0.0f) {
+ entryWidth = 0.0f;
} else {
- entryWidth = Math.max(mMinTickWidth, (int) (width * e.percentage));
+ entryWidth = Math.max(mMinTickWidth, width * e.percentage);
}
- final int nextX = lastX + entryWidth;
- if (nextX >= right) {
- break;
+ 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);
}
}
- canvas.drawRect(lastX, top, lastX + width, bottom, mEmptyPaint);
+ canvas.drawRect(lastX, top, right, bottom, mEmptyPaint);
}
/**
* Sets the background for this chart. Callers are responsible for later
* calling {@link #invalidate()}.
*/
+ @Override
public void setBackgroundColor(int color) {
mEmptyPaint.setColor(color);
}
public UsageBarPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- setWidgetLayoutResource(R.layout.preference_memoryusage);
+ setLayoutResource(R.layout.preference_memoryusage);
}
public UsageBarPreference(Context context) {
super(context);
- setWidgetLayoutResource(R.layout.preference_memoryusage);
+ setLayoutResource(R.layout.preference_memoryusage);
}
public UsageBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- setWidgetLayoutResource(R.layout.preference_memoryusage);
+ setLayoutResource(R.layout.preference_memoryusage);
}
public void addEntry(float percentage, int color) {