OSDN Git Service

Remove guava dependency to speed up build.
[android-x86/packages-apps-Settings.git] / src / com / android / settings / deviceinfo / UsageBarPreference.java
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.settings.deviceinfo;
18
19 import android.content.Context;
20 import android.preference.Preference;
21 import android.util.AttributeSet;
22 import android.view.View;
23
24 import com.android.settings.R;
25 import com.google.android.collect.Lists;
26
27 import java.util.Collections;
28 import java.util.List;
29
30 /**
31  * Creates a percentage bar chart inside a preference.
32  */
33 public class UsageBarPreference extends Preference {
34     private PercentageBarChart mChart = null;
35
36     private final List<PercentageBarChart.Entry> mEntries = Lists.newArrayList();
37
38     public UsageBarPreference(Context context, AttributeSet attrs, int defStyle) {
39         super(context, attrs, defStyle);
40         setLayoutResource(R.layout.preference_memoryusage);
41     }
42
43     public UsageBarPreference(Context context) {
44         super(context);
45         setLayoutResource(R.layout.preference_memoryusage);
46     }
47
48     public UsageBarPreference(Context context, AttributeSet attrs) {
49         super(context, attrs);
50         setLayoutResource(R.layout.preference_memoryusage);
51     }
52
53     public void addEntry(int order, float percentage, int color) {
54         mEntries.add(PercentageBarChart.createEntry(order, percentage, color));
55         Collections.sort(mEntries);
56     }
57
58     @Override
59     protected void onBindView(View view) {
60         super.onBindView(view);
61
62         mChart = (PercentageBarChart) view.findViewById(R.id.percentage_bar_chart);
63         mChart.setEntries(mEntries);
64     }
65
66     public void commit() {
67         if (mChart != null) {
68             mChart.invalidate();
69         }
70     }
71
72     public void clear() {
73         mEntries.clear();
74     }
75 }