OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.download.ui; | 5 package org.chromium.chrome.browser.download.ui; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.ColorStateList; | 8 import android.content.res.ColorStateList; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
11 import android.text.format.Formatter; | 11 import android.text.format.Formatter; |
12 import android.util.AttributeSet; | 12 import android.util.AttributeSet; |
13 import android.view.View; | 13 import android.view.View; |
14 import android.widget.LinearLayout; | 14 import android.widget.LinearLayout; |
15 import android.widget.TextView; | 15 import android.widget.TextView; |
16 | 16 |
17 import org.chromium.base.ApiCompatibilityUtils; | 17 import org.chromium.base.ApiCompatibilityUtils; |
18 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
19 import org.chromium.chrome.browser.download.DownloadUtils; | 19 import org.chromium.chrome.browser.download.DownloadUtils; |
20 import org.chromium.chrome.browser.widget.MaterialProgressBar; | 20 import org.chromium.chrome.browser.widget.MaterialProgressBar; |
21 import org.chromium.chrome.browser.widget.TintedImageButton; | 21 import org.chromium.chrome.browser.widget.TintedImageButton; |
22 import org.chromium.chrome.browser.widget.TintedImageView; | 22 import org.chromium.chrome.browser.widget.TintedImageView; |
23 import org.chromium.chrome.browser.widget.selection.SelectableItemView; | 23 import org.chromium.chrome.browser.widget.selection.SelectableItemView; |
24 import org.chromium.ui.UiUtils; | 24 import org.chromium.ui.UiUtils; |
| 25 import org.chromium.ui.base.DeviceFormFactor; |
25 | 26 |
26 /** | 27 /** |
27 * The view for a downloaded item displayed in the Downloads list. | 28 * The view for a downloaded item displayed in the Downloads list. |
28 */ | 29 */ |
29 public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
per> | 30 public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
per> |
30 implements ThumbnailProvider.ThumbnailRequest { | 31 implements ThumbnailProvider.ThumbnailRequest { |
31 private final int mMargin; | 32 private final int mMargin; |
32 private final int mIconBackgroundColor; | 33 private final int mIconBackgroundColor; |
33 private final int mIconBackgroundColorSelected; | 34 private final int mIconBackgroundColorSelected; |
34 private final ColorStateList mIconForegroundColorList; | 35 private final ColorStateList mIconForegroundColorList; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 mItem.pause(); | 99 mItem.pause(); |
99 } | 100 } |
100 } | 101 } |
101 }); | 102 }); |
102 mCancelButton.setOnClickListener(new View.OnClickListener() { | 103 mCancelButton.setOnClickListener(new View.OnClickListener() { |
103 @Override | 104 @Override |
104 public void onClick(View v) { | 105 public void onClick(View v) { |
105 mItem.cancel(); | 106 mItem.cancel(); |
106 } | 107 } |
107 }); | 108 }); |
| 109 |
| 110 if (!DeviceFormFactor.isLargeTablet(getContext())) { |
| 111 setLateralMarginsForDefaultDisplay(mLayoutContainer); |
| 112 } |
108 } | 113 } |
109 | 114 |
110 @Override | 115 @Override |
111 public String getFilePath() { | 116 public String getFilePath() { |
112 return mItem == null ? null : mItem.getFilePath(); | 117 return mItem == null ? null : mItem.getFilePath(); |
113 } | 118 } |
114 | 119 |
115 @Override | 120 @Override |
116 public void onThumbnailRetrieved(String filePath, Bitmap thumbnail) { | 121 public void onThumbnailRetrieved(String filePath, Bitmap thumbnail) { |
117 if (TextUtils.equals(getFilePath(), filePath) && thumbnail != null | 122 if (TextUtils.equals(getFilePath(), filePath) && thumbnail != null |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 mDownloadPercentageView.setText(null); | 192 mDownloadPercentageView.setText(null); |
188 ApiCompatibilityUtils.setMarginEnd( | 193 ApiCompatibilityUtils.setMarginEnd( |
189 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa
rams(), 0); | 194 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa
rams(), 0); |
190 } else { | 195 } else { |
191 mDownloadPercentageView.setText( | 196 mDownloadPercentageView.setText( |
192 DownloadUtils.getPercentageString(item.getDownloadProgre
ss())); | 197 DownloadUtils.getPercentageString(item.getDownloadProgre
ss())); |
193 ApiCompatibilityUtils.setMarginEnd( | 198 ApiCompatibilityUtils.setMarginEnd( |
194 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa
rams(), mMargin); | 199 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa
rams(), mMargin); |
195 } | 200 } |
196 } | 201 } |
| 202 |
| 203 setBackgroundResourceForGroupPosition( |
| 204 getItem().isFirstInGroup(), getItem().isLastInGroup()); |
197 } | 205 } |
198 | 206 |
199 /** | 207 /** |
200 * @param thumbnail The Bitmap to use for the icon ImageView. | 208 * @param thumbnail The Bitmap to use for the icon ImageView. |
201 */ | 209 */ |
202 public void setThumbnailBitmap(Bitmap thumbnail) { | 210 public void setThumbnailBitmap(Bitmap thumbnail) { |
203 mThumbnailBitmap = thumbnail; | 211 mThumbnailBitmap = thumbnail; |
204 updateIconView(); | 212 updateIconView(); |
205 } | 213 } |
206 | 214 |
(...skipping 10 matching lines...) Expand all Loading... |
217 return true; | 225 return true; |
218 } | 226 } |
219 } | 227 } |
220 | 228 |
221 @Override | 229 @Override |
222 public void setChecked(boolean checked) { | 230 public void setChecked(boolean checked) { |
223 super.setChecked(checked); | 231 super.setChecked(checked); |
224 updateIconView(); | 232 updateIconView(); |
225 } | 233 } |
226 | 234 |
| 235 @Override |
| 236 public void setBackgroundResourceForGroupPosition( |
| 237 boolean isFirstInGroup, boolean isLastInGroup) { |
| 238 if (DeviceFormFactor.isLargeTablet(getContext())) return; |
| 239 super.setBackgroundResourceForGroupPosition(isFirstInGroup, isLastInGrou
p); |
| 240 } |
| 241 |
227 private void updateIconView() { | 242 private void updateIconView() { |
228 if (isChecked()) { | 243 if (isChecked()) { |
229 mIconView.setBackgroundColor(mIconBackgroundColorSelected); | 244 mIconView.setBackgroundColor(mIconBackgroundColorSelected); |
230 mIconView.setImageResource(R.drawable.ic_check_googblue_24dp); | 245 mIconView.setImageResource(R.drawable.ic_check_googblue_24dp); |
231 mIconView.setTint(mIconForegroundColorList); | 246 mIconView.setTint(mIconForegroundColorList); |
232 } else if (mThumbnailBitmap != null) { | 247 } else if (mThumbnailBitmap != null) { |
233 assert !mThumbnailBitmap.isRecycled(); | 248 assert !mThumbnailBitmap.isRecycled(); |
234 mIconView.setBackground(null); | 249 mIconView.setBackground(null); |
235 mIconView.setImageBitmap(mThumbnailBitmap); | 250 mIconView.setImageBitmap(mThumbnailBitmap); |
236 mIconView.setTint(null); | 251 mIconView.setTint(null); |
237 } else { | 252 } else { |
238 mIconView.setBackgroundColor(mIconBackgroundColor); | 253 mIconView.setBackgroundColor(mIconBackgroundColor); |
239 mIconView.setImageResource(mIconResId); | 254 mIconView.setImageResource(mIconResId); |
240 mIconView.setTint(mIconForegroundColorList); | 255 mIconView.setTint(mIconForegroundColorList); |
241 } | 256 } |
242 } | 257 } |
243 | 258 |
244 private void showLayout(View layoutToShow) { | 259 private void showLayout(View layoutToShow) { |
245 if (mLayoutCompleted != layoutToShow) UiUtils.removeViewFromParent(mLayo
utCompleted); | 260 if (mLayoutCompleted != layoutToShow) UiUtils.removeViewFromParent(mLayo
utCompleted); |
246 if (mLayoutInProgress != layoutToShow) UiUtils.removeViewFromParent(mLay
outInProgress); | 261 if (mLayoutInProgress != layoutToShow) UiUtils.removeViewFromParent(mLay
outInProgress); |
247 | 262 |
248 if (layoutToShow.getParent() == null) { | 263 if (layoutToShow.getParent() == null) { |
249 LinearLayout.LayoutParams params = | 264 LinearLayout.LayoutParams params = |
250 new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT); | 265 new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT); |
251 params.weight = 1; | 266 params.weight = 1; |
252 mLayoutContainer.addView(layoutToShow, params); | 267 mLayoutContainer.addView(layoutToShow, params); |
253 } | 268 } |
254 } | 269 } |
255 } | 270 } |
OLD | NEW |