2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.deviceinfo;
19 import android.content.Context;
20 import android.preference.Preference;
21 import android.util.AttributeSet;
22 import android.view.View;
24 import com.android.settings.R;
25 import com.google.android.collect.Lists;
27 import java.util.Collections;
28 import java.util.List;
31 * Creates a percentage bar chart inside a preference.
33 public class UsageBarPreference extends Preference {
34 private PercentageBarChart mChart = null;
36 private final List<PercentageBarChart.Entry> mEntries = Lists.newArrayList();
38 public UsageBarPreference(Context context, AttributeSet attrs, int defStyle) {
39 super(context, attrs, defStyle);
40 setLayoutResource(R.layout.preference_memoryusage);
43 public UsageBarPreference(Context context) {
45 setLayoutResource(R.layout.preference_memoryusage);
48 public UsageBarPreference(Context context, AttributeSet attrs) {
49 super(context, attrs);
50 setLayoutResource(R.layout.preference_memoryusage);
53 public void addEntry(int order, float percentage, int color) {
54 mEntries.add(PercentageBarChart.createEntry(order, percentage, color));
55 Collections.sort(mEntries);
59 protected void onBindView(View view) {
60 super.onBindView(view);
62 mChart = (PercentageBarChart) view.findViewById(R.id.percentage_bar_chart);
63 mChart.setEntries(mEntries);
66 public void commit() {