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. | |
35 // This should be in sync with the same in DataReductionProxyDataUseObserver . | |
36 private static final String OTHER_HOST_NAME = "Other"; | |
rajendrant
2017/06/20 23:24:25
Not sure if a new string should be added in androi
megjablon
2017/06/20 23:45:46
This should definitely be translated. It will prob
rajendrant
2017/06/21 00:30:31
OK. I am adding an entry in android_chrome_strings
| |
37 | |
33 private int mNumDataUseItemsToDisplay = 10; | 38 private int mNumDataUseItemsToDisplay = 10; |
34 | 39 |
35 private TableLayout mTableLayout; | 40 private TableLayout mTableLayout; |
36 private TextView mDataUsedTitle; | 41 private TextView mDataUsedTitle; |
37 private TextView mDataSavedTitle; | 42 private TextView mDataSavedTitle; |
38 private List<DataReductionDataUseItem> mDataUseItems; | 43 private List<DataReductionDataUseItem> mDataUseItems; |
39 @ColorInt | 44 @ColorInt |
40 private int mTextColor; | 45 private int mTextColor; |
41 @ColorInt | 46 @ColorInt |
42 private int mLightTextColor; | 47 private int mLightTextColor; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 } | 127 } |
123 return drawables[2]; | 128 return drawables[2]; |
124 } | 129 } |
125 | 130 |
126 /** | 131 /** |
127 * Sorts the DataReductionDataUseItems by most to least data used. | 132 * Sorts the DataReductionDataUseItems by most to least data used. |
128 */ | 133 */ |
129 private static final class DataUsedComparator | 134 private static final class DataUsedComparator |
130 implements Comparator<DataReductionDataUseItem>, Serializable { | 135 implements Comparator<DataReductionDataUseItem>, Serializable { |
131 @Override | 136 @Override |
132 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { | 137 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { |
megjablon
2017/06/20 23:45:46
Please add a comment as to what this is doing. At
rajendrant
2017/06/21 00:30:31
Done.
| |
133 if (lhs.getDataUsed() < rhs.getDataUsed()) { | 138 if (OTHER_HOST_NAME.equals(lhs.getHostname())) { |
139 return 1; | |
140 } else if (OTHER_HOST_NAME.equals(rhs.getHostname())) { | |
141 return -1; | |
142 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { | |
134 return 1; | 143 return 1; |
135 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { | 144 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { |
136 return -1; | 145 return -1; |
137 } | 146 } |
138 return 0; | 147 return 0; |
139 } | 148 } |
140 } | 149 } |
141 | 150 |
142 /** | 151 /** |
143 * Sorts the DataReductionDataUseItems by most to least data saved. If data saved is equal, most | 152 * 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. | 153 * likely because both items have zero data saving, then sort by data used. |
145 */ | 154 */ |
146 private static class DataSavedComparator | 155 private static class DataSavedComparator |
147 implements Comparator<DataReductionDataUseItem>, Serializable { | 156 implements Comparator<DataReductionDataUseItem>, Serializable { |
148 @Override | 157 @Override |
149 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { | 158 public int compare(DataReductionDataUseItem lhs, DataReductionDataUseIte m rhs) { |
megjablon
2017/06/20 23:45:46
Also a comment here.
rajendrant
2017/06/21 00:30:31
Done.
| |
150 if (lhs.getDataSaved() < rhs.getDataSaved()) { | 159 if (OTHER_HOST_NAME.equals(lhs.getHostname())) { |
160 return 1; | |
161 } else if (OTHER_HOST_NAME.equals(rhs.getHostname())) { | |
162 return -1; | |
163 } else if (lhs.getDataSaved() < rhs.getDataSaved()) { | |
151 return 1; | 164 return 1; |
152 } else if (lhs.getDataSaved() > rhs.getDataSaved()) { | 165 } else if (lhs.getDataSaved() > rhs.getDataSaved()) { |
153 return -1; | 166 return -1; |
154 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { | 167 } else if (lhs.getDataUsed() < rhs.getDataUsed()) { |
155 return 1; | 168 return 1; |
156 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { | 169 } else if (lhs.getDataUsed() > rhs.getDataUsed()) { |
157 return -1; | 170 return -1; |
158 } | 171 } |
159 return 0; | 172 return 0; |
160 } | 173 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 mNumDataUseItemsToDisplay += NUM_DATA_USE_ITEMS_TO_ADD; | 234 mNumDataUseItemsToDisplay += NUM_DATA_USE_ITEMS_TO_ADD; |
222 updateSiteBreakdown(); | 235 updateSiteBreakdown(); |
223 } | 236 } |
224 }); | 237 }); |
225 | 238 |
226 mTableLayout.addView(row, mNumDataUseItemsToDisplay + 1); | 239 mTableLayout.addView(row, mNumDataUseItemsToDisplay + 1); |
227 } | 240 } |
228 | 241 |
229 mTableLayout.requestLayout(); | 242 mTableLayout.requestLayout(); |
230 } | 243 } |
231 } | 244 } |
OLD | NEW |