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; |
11 import android.util.AttributeSet; | 11 import android.util.AttributeSet; |
12 import android.view.LayoutInflater; | 12 import android.view.LayoutInflater; |
13 import android.view.View; | 13 import android.view.View; |
14 import android.widget.LinearLayout; | 14 import android.widget.LinearLayout; |
15 import android.widget.TableLayout; | 15 import android.widget.TableLayout; |
16 import android.widget.TableRow; | 16 import android.widget.TableRow; |
17 import android.widget.TextView; | 17 import android.widget.TextView; |
18 | 18 |
19 import org.chromium.base.ApiCompatibilityUtils; | 19 import org.chromium.base.ApiCompatibilityUtils; |
20 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
21 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxyAndroidUIStri ngs; | |
21 | 22 |
22 import java.io.Serializable; | 23 import java.io.Serializable; |
23 import java.util.Collections; | 24 import java.util.Collections; |
24 import java.util.Comparator; | 25 import java.util.Comparator; |
25 import java.util.List; | 26 import java.util.List; |
26 | 27 |
27 /** | 28 /** |
28 * A site breakdown view to be used by the Data Saver settings page. It displays the top ten sites | 29 * 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. | 30 * with the most data use or data savings. |
30 */ | 31 */ |
31 public class DataReductionSiteBreakdownView extends LinearLayout { | 32 public class DataReductionSiteBreakdownView extends LinearLayout { |
32 private static final int NUM_DATA_USE_ITEMS_TO_ADD = 10; | 33 private static final int NUM_DATA_USE_ITEMS_TO_ADD = 10; |
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 = DataReductionProxyAndroidUIStrings.getOtherHostNa me(); | |
megjablon
2017/06/27 18:03:52
Since the translated string is being added in Andr
Raj
2017/06/27 18:24:08
Done
| |
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 |