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 /* Hostname used for the other bucket which consists of chrome-services traf fic. | |
gone
2017/06/27 21:47:25
Fix javadoc syntax. See line 27.
Raj
2017/06/27 22:09:02
Done
Looks like google java style allows this, whi
| |
35 * This should be in sync with the same in DataReductionProxyDataUseObserver . | |
36 */ | |
37 private static final String OTHER_HOST_NAME = "Other"; | |
38 | |
33 private int mNumDataUseItemsToDisplay = 10; | 39 private int mNumDataUseItemsToDisplay = 10; |
34 | 40 |
35 private TableLayout mTableLayout; | 41 private TableLayout mTableLayout; |
36 private TextView mDataUsedTitle; | 42 private TextView mDataUsedTitle; |
37 private TextView mDataSavedTitle; | 43 private TextView mDataSavedTitle; |
38 private List<DataReductionDataUseItem> mDataUseItems; | 44 private List<DataReductionDataUseItem> mDataUseItems; |
39 @ColorInt | 45 @ColorInt |
40 private int mTextColor; | 46 private int mTextColor; |
41 @ColorInt | 47 @ColorInt |
42 private int mLightTextColor; | 48 private int mLightTextColor; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 } | 88 } |
83 | 89 |
84 /** | 90 /** |
85 * Display the data use items once they have been fetched from the compressi on stats. | 91 * 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. | 92 * @param items A list of items split by hostname to show in the breakdown. |
87 */ | 93 */ |
88 public void onQueryDataUsageComplete(List<DataReductionDataUseItem> items) { | 94 public void onQueryDataUsageComplete(List<DataReductionDataUseItem> items) { |
89 mDataUseItems = items; | 95 mDataUseItems = items; |
90 setTextViewUnsortedAttributes(mDataUsedTitle); | 96 setTextViewUnsortedAttributes(mDataUsedTitle); |
91 setTextViewSortedAttributes(mDataSavedTitle); | 97 setTextViewSortedAttributes(mDataSavedTitle); |
92 Collections.sort(items, new DataSavedComparator()); | 98 Collections.sort(mDataUseItems, new DataSavedComparator()); |
93 if (mDataUseItems.size() == 0) { | 99 if (mDataUseItems.size() == 0) { |
94 setVisibility(GONE); | 100 setVisibility(GONE); |
95 } else { | 101 } else { |
96 setVisibility(VISIBLE); | 102 setVisibility(VISIBLE); |
97 updateSiteBreakdown(); | 103 updateSiteBreakdown(); |
98 DataReductionProxyUma.dataReductionProxyUIAction( | 104 DataReductionProxyUma.dataReductionProxyUIAction( |
99 DataReductionProxyUma.ACTION_SITE_BREAKDOWN_DISPLAYED); | 105 DataReductionProxyUma.ACTION_SITE_BREAKDOWN_DISPLAYED); |
100 } | 106 } |
101 } | 107 } |
102 | 108 |
(...skipping 20 matching lines...) Expand all Loading... | |
123 return drawables[2]; | 129 return drawables[2]; |
124 } | 130 } |
125 | 131 |
126 /** | 132 /** |
127 * Sorts the DataReductionDataUseItems by most to least data used. | 133 * Sorts the DataReductionDataUseItems by most to least data used. |
128 */ | 134 */ |
129 private static final class DataUsedComparator | 135 private static final class DataUsedComparator |
130 implements Comparator<DataReductionDataUseItem>, Serializable { | 136 implements Comparator<DataReductionDataUseItem>, Serializable { |
131 @Override | 137 @Override |
132 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { | 138 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { |
133 if (lhs.getDataUsed() < rhs.getDataUsed()) { | 139 // Force the 'Other' category to the bottom of the list. |
140 if (OTHER_HOST_NAME.equals(lhs.getHostname())) { | |
141 return 1; | |
142 } else if (OTHER_HOST_NAME.equals(rhs.getHostname())) { | |
143 return -1; | |
144 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { | |
134 return 1; | 145 return 1; |
135 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { | 146 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { |
136 return -1; | 147 return -1; |
137 } | 148 } |
138 return 0; | 149 return 0; |
139 } | 150 } |
140 } | 151 } |
141 | 152 |
142 /** | 153 /** |
143 * Sorts the DataReductionDataUseItems by most to least data saved. If data saved is equal, most | 154 * 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. | 155 * likely because both items have zero data saving, then sort by data used. |
145 */ | 156 */ |
146 private static class DataSavedComparator | 157 private static class DataSavedComparator |
147 implements Comparator<DataReductionDataUseItem>, Serializable { | 158 implements Comparator<DataReductionDataUseItem>, Serializable { |
148 @Override | 159 @Override |
149 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { | 160 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { |
150 if (lhs.getDataSaved() < rhs.getDataSaved()) { | 161 // Force the 'Other' category to the bottom of the list. |
162 if (OTHER_HOST_NAME.equals(lhs.getHostname())) { | |
163 return 1; | |
164 } else if (OTHER_HOST_NAME.equals(rhs.getHostname())) { | |
165 return -1; | |
166 } else if (lhs.getDataSaved() < rhs.getDataSaved()) { | |
151 return 1; | 167 return 1; |
152 } else if (lhs.getDataSaved() > rhs.getDataSaved()) { | 168 } else if (lhs.getDataSaved() > rhs.getDataSaved()) { |
153 return -1; | 169 return -1; |
154 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { | 170 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { |
155 return 1; | 171 return 1; |
156 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { | 172 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { |
157 return -1; | 173 return -1; |
158 } | 174 } |
159 return 0; | 175 return 0; |
160 } | 176 } |
(...skipping 12 matching lines...) Expand all Loading... | |
173 | 189 |
174 for (int i = 0; i < mDataUseItems.size(); i++) { | 190 for (int i = 0; i < mDataUseItems.size(); i++) { |
175 if (i < mNumDataUseItemsToDisplay) { | 191 if (i < mNumDataUseItemsToDisplay) { |
176 TableRow row = (TableRow) LayoutInflater.from(getContext()) | 192 TableRow row = (TableRow) LayoutInflater.from(getContext()) |
177 .inflate(R.layout.data_usage_breakdown_ro w, null); | 193 .inflate(R.layout.data_usage_breakdown_ro w, null); |
178 | 194 |
179 TextView hostnameView = (TextView) row.findViewById(R.id.site_ho stname); | 195 TextView hostnameView = (TextView) row.findViewById(R.id.site_ho stname); |
180 TextView dataUsedView = (TextView) row.findViewById(R.id.site_da ta_used); | 196 TextView dataUsedView = (TextView) row.findViewById(R.id.site_da ta_used); |
181 TextView dataSavedView = (TextView) row.findViewById(R.id.site_d ata_saved); | 197 TextView dataSavedView = (TextView) row.findViewById(R.id.site_d ata_saved); |
182 | 198 |
183 hostnameView.setText(mDataUseItems.get(i).getHostname()); | 199 String hostName = mDataUseItems.get(i).getHostname(); |
200 if (OTHER_HOST_NAME.equals(hostName)) { | |
201 hostName = getResources().getString( | |
202 R.string.data_reduction_breakdown_other_host_name); | |
203 } | |
204 hostnameView.setText(hostName); | |
184 dataUsedView.setText(mDataUseItems.get(i).getFormattedDataUsed(g etContext())); | 205 dataUsedView.setText(mDataUseItems.get(i).getFormattedDataUsed(g etContext())); |
185 dataSavedView.setText(mDataUseItems.get(i).getFormattedDataSaved (getContext())); | 206 dataSavedView.setText(mDataUseItems.get(i).getFormattedDataSaved (getContext())); |
186 | 207 |
187 mTableLayout.addView(row, i + 1); | 208 mTableLayout.addView(row, i + 1); |
188 } else { | 209 } else { |
189 numRemainingSites++; | 210 numRemainingSites++; |
190 everythingElseDataUsage += mDataUseItems.get(i).getDataUsed(); | 211 everythingElseDataUsage += mDataUseItems.get(i).getDataUsed(); |
191 everythingElseDataSavings += mDataUseItems.get(i).getDataSaved() ; | 212 everythingElseDataSavings += mDataUseItems.get(i).getDataSaved() ; |
192 } | 213 } |
193 } | 214 } |
(...skipping 27 matching lines...) Expand all Loading... | |
221 mNumDataUseItemsToDisplay += NUM_DATA_USE_ITEMS_TO_ADD; | 242 mNumDataUseItemsToDisplay += NUM_DATA_USE_ITEMS_TO_ADD; |
222 updateSiteBreakdown(); | 243 updateSiteBreakdown(); |
223 } | 244 } |
224 }); | 245 }); |
225 | 246 |
226 mTableLayout.addView(row, mNumDataUseItemsToDisplay + 1); | 247 mTableLayout.addView(row, mNumDataUseItemsToDisplay + 1); |
227 } | 248 } |
228 | 249 |
229 mTableLayout.requestLayout(); | 250 mTableLayout.requestLayout(); |
230 } | 251 } |
231 } | 252 } |
OLD | NEW |