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 11 matching lines...) Expand all Loading... |
22 import java.io.Serializable; | 22 import java.io.Serializable; |
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_DISPLAY = 10; | 32 private static final int NUM_DATA_USE_ITEMS_TO_ADD = 10; |
| 33 private int mNumDataUseItemsToDisplay = 10; |
33 | 34 |
34 private TableLayout mTableLayout; | 35 private TableLayout mTableLayout; |
35 private TextView mDataUsedTitle; | 36 private TextView mDataUsedTitle; |
36 private TextView mDataSavedTitle; | 37 private TextView mDataSavedTitle; |
37 private List<DataReductionDataUseItem> mDataUseItems; | 38 private List<DataReductionDataUseItem> mDataUseItems; |
38 @ColorInt | 39 @ColorInt |
39 private int mTextColor; | 40 private int mTextColor; |
40 @ColorInt | 41 @ColorInt |
41 private int mLightTextColor; | 42 private int mLightTextColor; |
42 | 43 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 160 |
160 setVisibility(VISIBLE); | 161 setVisibility(VISIBLE); |
161 // Remove all old rows except the header. | 162 // Remove all old rows except the header. |
162 mTableLayout.removeViews(1, mTableLayout.getChildCount() - 1); | 163 mTableLayout.removeViews(1, mTableLayout.getChildCount() - 1); |
163 | 164 |
164 int numRemainingSites = 0; | 165 int numRemainingSites = 0; |
165 int everythingElseDataUsage = 0; | 166 int everythingElseDataUsage = 0; |
166 int everythingElseDataSavings = 0; | 167 int everythingElseDataSavings = 0; |
167 | 168 |
168 for (int i = 0; i < mDataUseItems.size(); i++) { | 169 for (int i = 0; i < mDataUseItems.size(); i++) { |
169 if (i < NUM_DATA_USE_ITEMS_TO_DISPLAY) { | 170 if (i < mNumDataUseItemsToDisplay) { |
170 TableRow row = (TableRow) LayoutInflater.from(getContext()) | 171 TableRow row = (TableRow) LayoutInflater.from(getContext()) |
171 .inflate(R.layout.data_usage_breakdown_ro
w, null); | 172 .inflate(R.layout.data_usage_breakdown_ro
w, null); |
172 | 173 |
173 TextView hostnameView = (TextView) row.findViewById(R.id.site_ho
stname); | 174 TextView hostnameView = (TextView) row.findViewById(R.id.site_ho
stname); |
174 TextView dataUsedView = (TextView) row.findViewById(R.id.site_da
ta_used); | 175 TextView dataUsedView = (TextView) row.findViewById(R.id.site_da
ta_used); |
175 TextView dataSavedView = (TextView) row.findViewById(R.id.site_d
ata_saved); | 176 TextView dataSavedView = (TextView) row.findViewById(R.id.site_d
ata_saved); |
176 | 177 |
177 hostnameView.setText(mDataUseItems.get(i).getHostname()); | 178 hostnameView.setText(mDataUseItems.get(i).getHostname()); |
178 dataUsedView.setText(mDataUseItems.get(i).getFormattedDataUsed(g
etContext())); | 179 dataUsedView.setText(mDataUseItems.get(i).getFormattedDataUsed(g
etContext())); |
179 dataSavedView.setText(mDataUseItems.get(i).getFormattedDataSaved
(getContext())); | 180 dataSavedView.setText(mDataUseItems.get(i).getFormattedDataSaved
(getContext())); |
(...skipping 20 matching lines...) Expand all Loading... |
200 dataSavedView.setText( | 201 dataSavedView.setText( |
201 Formatter.formatFileSize(getContext(), everythingElseDataSav
ings)); | 202 Formatter.formatFileSize(getContext(), everythingElseDataSav
ings)); |
202 | 203 |
203 int lightActiveColor = ApiCompatibilityUtils.getColor( | 204 int lightActiveColor = ApiCompatibilityUtils.getColor( |
204 getContext().getResources(), R.color.light_active_color); | 205 getContext().getResources(), R.color.light_active_color); |
205 | 206 |
206 hostnameView.setTextColor(lightActiveColor); | 207 hostnameView.setTextColor(lightActiveColor); |
207 dataUsedView.setTextColor(lightActiveColor); | 208 dataUsedView.setTextColor(lightActiveColor); |
208 dataSavedView.setTextColor(lightActiveColor); | 209 dataSavedView.setTextColor(lightActiveColor); |
209 | 210 |
210 mTableLayout.addView(row, NUM_DATA_USE_ITEMS_TO_DISPLAY + 1); | 211 row.setOnClickListener(new OnClickListener() { |
| 212 @Override |
| 213 public void onClick(View v) { |
| 214 mNumDataUseItemsToDisplay += NUM_DATA_USE_ITEMS_TO_ADD; |
| 215 updateSiteBreakdown(); |
| 216 } |
| 217 }); |
| 218 |
| 219 mTableLayout.addView(row, mNumDataUseItemsToDisplay + 1); |
211 } | 220 } |
212 | 221 |
213 mTableLayout.requestLayout(); | 222 mTableLayout.requestLayout(); |
214 } | 223 } |
215 } | 224 } |
OLD | NEW |