Merge "Fixes in UsageBarPreference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
e3b5428611
@@ -13,17 +13,24 @@
|
||||
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>
|
||||
|
@@ -27,9 +27,9 @@ import android.app.DownloadManager;
|
||||
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;
|
||||
|
@@ -71,20 +71,21 @@ public class PercentageBarChart extends View {
|
||||
|
||||
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);
|
||||
@@ -92,13 +93,14 @@ public class PercentageBarChart extends View {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@@ -36,17 +36,17 @@ public class UsageBarPreference extends Preference {
|
||||
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user