OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.preferences.datareduction; | 5 package org.chromium.chrome.browser.preferences.datareduction; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.drawable.Drawable; | 8 import android.graphics.drawable.Drawable; |
9 import android.support.annotation.ColorInt; | 9 import android.support.annotation.ColorInt; |
10 import android.text.format.Formatter; | 10 import android.text.format.Formatter; |
(...skipping 12 matching lines...) Expand all Loading... |
23 import java.util.Collections; | 23 import java.util.Collections; |
24 import java.util.Comparator; | 24 import java.util.Comparator; |
25 import java.util.List; | 25 import java.util.List; |
26 | 26 |
27 /** | 27 /** |
28 * A site breakdown view to be used by the Data Saver settings page. It displays
the top ten sites | 28 * A site breakdown view to be used by the Data Saver settings page. It displays
the top ten sites |
29 * with the most data use or data savings. | 29 * with the most data use or data savings. |
30 */ | 30 */ |
31 public class DataReductionSiteBreakdownView extends LinearLayout { | 31 public class DataReductionSiteBreakdownView extends LinearLayout { |
32 private static final int NUM_DATA_USE_ITEMS_TO_ADD = 10; | 32 private static final int NUM_DATA_USE_ITEMS_TO_ADD = 10; |
| 33 |
| 34 /** |
| 35 * Hostname used for the other bucket which consists of chrome-services traf
fic. |
| 36 * This should be in sync with the same in DataReductionProxyDataUseObserver
. |
| 37 */ |
| 38 private static final String OTHER_HOST_NAME = "Other"; |
| 39 |
33 private int mNumDataUseItemsToDisplay = 10; | 40 private int mNumDataUseItemsToDisplay = 10; |
34 | 41 |
35 private TableLayout mTableLayout; | 42 private TableLayout mTableLayout; |
36 private TextView mDataUsedTitle; | 43 private TextView mDataUsedTitle; |
37 private TextView mDataSavedTitle; | 44 private TextView mDataSavedTitle; |
38 private List<DataReductionDataUseItem> mDataUseItems; | 45 private List<DataReductionDataUseItem> mDataUseItems; |
39 @ColorInt | 46 @ColorInt |
40 private int mTextColor; | 47 private int mTextColor; |
41 @ColorInt | 48 @ColorInt |
42 private int mLightTextColor; | 49 private int mLightTextColor; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 89 } |
83 | 90 |
84 /** | 91 /** |
85 * Display the data use items once they have been fetched from the compressi
on stats. | 92 * Display the data use items once they have been fetched from the compressi
on stats. |
86 * @param items A list of items split by hostname to show in the breakdown. | 93 * @param items A list of items split by hostname to show in the breakdown. |
87 */ | 94 */ |
88 public void onQueryDataUsageComplete(List<DataReductionDataUseItem> items) { | 95 public void onQueryDataUsageComplete(List<DataReductionDataUseItem> items) { |
89 mDataUseItems = items; | 96 mDataUseItems = items; |
90 setTextViewUnsortedAttributes(mDataUsedTitle); | 97 setTextViewUnsortedAttributes(mDataUsedTitle); |
91 setTextViewSortedAttributes(mDataSavedTitle); | 98 setTextViewSortedAttributes(mDataSavedTitle); |
92 Collections.sort(items, new DataSavedComparator()); | 99 Collections.sort(mDataUseItems, new DataSavedComparator()); |
93 if (mDataUseItems.size() == 0) { | 100 if (mDataUseItems.size() == 0) { |
94 setVisibility(GONE); | 101 setVisibility(GONE); |
95 } else { | 102 } else { |
96 setVisibility(VISIBLE); | 103 setVisibility(VISIBLE); |
97 updateSiteBreakdown(); | 104 updateSiteBreakdown(); |
98 DataReductionProxyUma.dataReductionProxyUIAction( | 105 DataReductionProxyUma.dataReductionProxyUIAction( |
99 DataReductionProxyUma.ACTION_SITE_BREAKDOWN_DISPLAYED); | 106 DataReductionProxyUma.ACTION_SITE_BREAKDOWN_DISPLAYED); |
100 } | 107 } |
101 } | 108 } |
102 | 109 |
(...skipping 20 matching lines...) Expand all Loading... |
123 return drawables[2]; | 130 return drawables[2]; |
124 } | 131 } |
125 | 132 |
126 /** | 133 /** |
127 * Sorts the DataReductionDataUseItems by most to least data used. | 134 * Sorts the DataReductionDataUseItems by most to least data used. |
128 */ | 135 */ |
129 private static final class DataUsedComparator | 136 private static final class DataUsedComparator |
130 implements Comparator<DataReductionDataUseItem>, Serializable { | 137 implements Comparator<DataReductionDataUseItem>, Serializable { |
131 @Override | 138 @Override |
132 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte
m rhs) { | 139 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte
m rhs) { |
133 if (lhs.getDataUsed() < rhs.getDataUsed()) { | 140 // Force the 'Other' category to the bottom of the list. |
| 141 if (OTHER_HOST_NAME.equals(lhs.getHostname())) { |
| 142 return 1; |
| 143 } else if (OTHER_HOST_NAME.equals(rhs.getHostname())) { |
| 144 return -1; |
| 145 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { |
134 return 1; | 146 return 1; |
135 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { | 147 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { |
136 return -1; | 148 return -1; |
137 } | 149 } |
138 return 0; | 150 return 0; |
139 } | 151 } |
140 } | 152 } |
141 | 153 |
142 /** | 154 /** |
143 * Sorts the DataReductionDataUseItems by most to least data saved. If data
saved is equal, most | 155 * Sorts the DataReductionDataUseItems by most to least data saved. If data
saved is equal, most |
144 * likely because both items have zero data saving, then sort by data used. | 156 * likely because both items have zero data saving, then sort by data used. |
145 */ | 157 */ |
146 private static class DataSavedComparator | 158 private static class DataSavedComparator |
147 implements Comparator<DataReductionDataUseItem>, Serializable { | 159 implements Comparator<DataReductionDataUseItem>, Serializable { |
148 @Override | 160 @Override |
149 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte
m rhs) { | 161 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte
m rhs) { |
150 if (lhs.getDataSaved() < rhs.getDataSaved()) { | 162 // Force the 'Other' category to the bottom of the list. |
| 163 if (OTHER_HOST_NAME.equals(lhs.getHostname())) { |
| 164 return 1; |
| 165 } else if (OTHER_HOST_NAME.equals(rhs.getHostname())) { |
| 166 return -1; |
| 167 } else if (lhs.getDataSaved() < rhs.getDataSaved()) { |
151 return 1; | 168 return 1; |
152 } else if (lhs.getDataSaved() > rhs.getDataSaved()) { | 169 } else if (lhs.getDataSaved() > rhs.getDataSaved()) { |
153 return -1; | 170 return -1; |
154 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { | 171 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { |
155 return 1; | 172 return 1; |
156 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { | 173 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { |
157 return -1; | 174 return -1; |
158 } | 175 } |
159 return 0; | 176 return 0; |
160 } | 177 } |
(...skipping 12 matching lines...) Expand all Loading... |
173 | 190 |
174 for (int i = 0; i < mDataUseItems.size(); i++) { | 191 for (int i = 0; i < mDataUseItems.size(); i++) { |
175 if (i < mNumDataUseItemsToDisplay) { | 192 if (i < mNumDataUseItemsToDisplay) { |
176 TableRow row = (TableRow) LayoutInflater.from(getContext()) | 193 TableRow row = (TableRow) LayoutInflater.from(getContext()) |
177 .inflate(R.layout.data_usage_breakdown_ro
w, null); | 194 .inflate(R.layout.data_usage_breakdown_ro
w, null); |
178 | 195 |
179 TextView hostnameView = (TextView) row.findViewById(R.id.site_ho
stname); | 196 TextView hostnameView = (TextView) row.findViewById(R.id.site_ho
stname); |
180 TextView dataUsedView = (TextView) row.findViewById(R.id.site_da
ta_used); | 197 TextView dataUsedView = (TextView) row.findViewById(R.id.site_da
ta_used); |
181 TextView dataSavedView = (TextView) row.findViewById(R.id.site_d
ata_saved); | 198 TextView dataSavedView = (TextView) row.findViewById(R.id.site_d
ata_saved); |
182 | 199 |
183 hostnameView.setText(mDataUseItems.get(i).getHostname()); | 200 String hostName = mDataUseItems.get(i).getHostname(); |
| 201 if (OTHER_HOST_NAME.equals(hostName)) { |
| 202 hostName = getResources().getString( |
| 203 R.string.data_reduction_breakdown_other_host_name); |
| 204 } |
| 205 hostnameView.setText(hostName); |
184 dataUsedView.setText(mDataUseItems.get(i).getFormattedDataUsed(g
etContext())); | 206 dataUsedView.setText(mDataUseItems.get(i).getFormattedDataUsed(g
etContext())); |
185 dataSavedView.setText(mDataUseItems.get(i).getFormattedDataSaved
(getContext())); | 207 dataSavedView.setText(mDataUseItems.get(i).getFormattedDataSaved
(getContext())); |
186 | 208 |
187 mTableLayout.addView(row, i + 1); | 209 mTableLayout.addView(row, i + 1); |
188 } else { | 210 } else { |
189 numRemainingSites++; | 211 numRemainingSites++; |
190 everythingElseDataUsage += mDataUseItems.get(i).getDataUsed(); | 212 everythingElseDataUsage += mDataUseItems.get(i).getDataUsed(); |
191 everythingElseDataSavings += mDataUseItems.get(i).getDataSaved()
; | 213 everythingElseDataSavings += mDataUseItems.get(i).getDataSaved()
; |
192 } | 214 } |
193 } | 215 } |
(...skipping 27 matching lines...) Expand all Loading... |
221 mNumDataUseItemsToDisplay += NUM_DATA_USE_ITEMS_TO_ADD; | 243 mNumDataUseItemsToDisplay += NUM_DATA_USE_ITEMS_TO_ADD; |
222 updateSiteBreakdown(); | 244 updateSiteBreakdown(); |
223 } | 245 } |
224 }); | 246 }); |
225 | 247 |
226 mTableLayout.addView(row, mNumDataUseItemsToDisplay + 1); | 248 mTableLayout.addView(row, mNumDataUseItemsToDisplay + 1); |
227 } | 249 } |
228 | 250 |
229 mTableLayout.requestLayout(); | 251 mTableLayout.requestLayout(); |
230 } | 252 } |
231 } | 253 } |
OLD | NEW |