• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.settings.R;
20 import com.google.common.collect.Lists;
21 
22 import android.content.Context;
23 import android.preference.Preference;
24 import android.util.AttributeSet;
25 import android.view.View;
26 
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.List;
31 
32 /**
33  * Creates a percentage bar chart inside a preference.
34  */
35 public class UsageBarPreference extends Preference {
36     private PercentageBarChart mChart = null;
37 
38     private final List<PercentageBarChart.Entry> mEntries = Lists.newArrayList();
39 
UsageBarPreference(Context context, AttributeSet attrs, int defStyle)40     public UsageBarPreference(Context context, AttributeSet attrs, int defStyle) {
41         super(context, attrs, defStyle);
42         setLayoutResource(R.layout.preference_memoryusage);
43     }
44 
UsageBarPreference(Context context)45     public UsageBarPreference(Context context) {
46         super(context);
47         setLayoutResource(R.layout.preference_memoryusage);
48     }
49 
UsageBarPreference(Context context, AttributeSet attrs)50     public UsageBarPreference(Context context, AttributeSet attrs) {
51         super(context, attrs);
52         setLayoutResource(R.layout.preference_memoryusage);
53     }
54 
addEntry(int order, float percentage, int color)55     public void addEntry(int order, float percentage, int color) {
56         mEntries.add(PercentageBarChart.createEntry(order, percentage, color));
57         Collections.sort(mEntries);
58     }
59 
60     @Override
onBindView(View view)61     protected void onBindView(View view) {
62         super.onBindView(view);
63 
64         mChart = (PercentageBarChart) view.findViewById(R.id.percentage_bar_chart);
65         mChart.setEntries(mEntries);
66     }
67 
commit()68     public void commit() {
69         if (mChart != null) {
70             mChart.invalidate();
71         }
72     }
73 
clear()74     public void clear() {
75         mEntries.clear();
76     }
77 }
78