Chromium Code Reviews| 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.components.offline_items_collection.OfflineItem.Progress; | |
| 24 import org.chromium.ui.UiUtils; | 25 import org.chromium.ui.UiUtils; |
| 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; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 mHostnameView.setText(item.getDisplayHostname()); | 158 mHostnameView.setText(item.getDisplayHostname()); |
| 158 mFilesizeView.setText( | 159 mFilesizeView.setText( |
| 159 Formatter.formatFileSize(context, item.getFileSize())); | 160 Formatter.formatFileSize(context, item.getFileSize())); |
| 160 | 161 |
| 161 if (item.isComplete()) { | 162 if (item.isComplete()) { |
| 162 showLayout(mLayoutCompleted); | 163 showLayout(mLayoutCompleted); |
| 163 } else { | 164 } else { |
| 164 showLayout(mLayoutInProgress); | 165 showLayout(mLayoutInProgress); |
| 165 mDownloadStatusView.setText(item.getStatusString()); | 166 mDownloadStatusView.setText(item.getStatusString()); |
| 166 | 167 |
| 167 boolean isIndeterminate = item.isIndeterminate(); | 168 Progress progress = item.getDownloadProgress(); |
| 168 | 169 |
| 169 if (item.isPaused()) { | 170 if (item.isPaused()) { |
| 170 mPauseResumeButton.setImageResource(R.drawable.ic_play_arrow_whi te_24dp); | 171 mPauseResumeButton.setImageResource(R.drawable.ic_play_arrow_whi te_24dp); |
| 171 mPauseResumeButton.setContentDescription( | 172 mPauseResumeButton.setContentDescription( |
| 172 getContext().getString(R.string.download_notification_re sume_button)); | 173 getContext().getString(R.string.download_notification_re sume_button)); |
| 173 mProgressView.setIndeterminate(false); | 174 mProgressView.setIndeterminate(false); |
| 174 } else { | 175 } else { |
| 175 mPauseResumeButton.setImageResource(R.drawable.ic_pause_white_24 dp); | 176 mPauseResumeButton.setImageResource(R.drawable.ic_pause_white_24 dp); |
| 176 mPauseResumeButton.setContentDescription( | 177 mPauseResumeButton.setContentDescription( |
| 177 getContext().getString(R.string.download_notification_pa use_button)); | 178 getContext().getString(R.string.download_notification_pa use_button)); |
| 178 mProgressView.setIndeterminate(isIndeterminate); | 179 mProgressView.setIndeterminate(progress.isIndeterminate()); |
| 179 } | 180 } |
| 180 mProgressView.setProgress(item.getDownloadProgress()); | 181 |
| 182 if (!progress.isIndeterminate()) { | |
| 183 mProgressView.setProgress(progress.getPercentage()); | |
| 184 } | |
| 181 | 185 |
| 182 // Display the percentage downloaded in text form. | 186 // Display the percentage downloaded in text form. |
| 183 // To avoid problems with RelativeLayout not knowing how to place vi ews relative to | 187 // To avoid problems with RelativeLayout not knowing how to place vi ews relative to |
| 184 // removed views in the hierarchy, this code instead makes the perce ntage View's width | 188 // removed views in the hierarchy, this code instead makes the perce ntage View's width |
| 185 // to 0 by removing its text and eliminating the margin. | 189 // to 0 by removing its text and eliminating the margin. |
| 186 if (isIndeterminate) { | 190 if (progress.isIndeterminate()) { |
| 187 mDownloadPercentageView.setText(null); | 191 mDownloadPercentageView.setText(null); |
| 188 ApiCompatibilityUtils.setMarginEnd( | 192 ApiCompatibilityUtils.setMarginEnd( |
| 189 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa rams(), 0); | 193 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa rams(), 0); |
| 190 } else { | 194 } else { |
| 191 mDownloadPercentageView.setText( | 195 mDownloadPercentageView.setText( |
|
David Trainor- moved to gerrit
2017/05/09 05:36:01
Should we add a TODO and file a bug to investigate
shaktisahu
2017/05/09 19:04:32
I didn't get it. We are just showing the percentag
| |
| 192 DownloadUtils.getPercentageString(item.getDownloadProgre ss())); | 196 DownloadUtils.getPercentageString(progress.getPercentage ())); |
| 193 ApiCompatibilityUtils.setMarginEnd( | 197 ApiCompatibilityUtils.setMarginEnd( |
| 194 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa rams(), mMargin); | 198 (MarginLayoutParams) mDownloadPercentageView.getLayoutPa rams(), mMargin); |
| 195 } | 199 } |
| 196 } | 200 } |
| 197 | 201 |
| 198 setBackgroundResourceForGroupPosition( | 202 setBackgroundResourceForGroupPosition( |
| 199 getItem().isFirstInGroup(), getItem().isLastInGroup()); | 203 getItem().isFirstInGroup(), getItem().isLastInGroup()); |
| 200 } | 204 } |
| 201 | 205 |
| 202 /** | 206 /** |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 if (mLayoutInProgress != layoutToShow) UiUtils.removeViewFromParent(mLay outInProgress); | 253 if (mLayoutInProgress != layoutToShow) UiUtils.removeViewFromParent(mLay outInProgress); |
| 250 | 254 |
| 251 if (layoutToShow.getParent() == null) { | 255 if (layoutToShow.getParent() == null) { |
| 252 LinearLayout.LayoutParams params = | 256 LinearLayout.LayoutParams params = |
| 253 new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT); | 257 new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT); |
| 254 params.weight = 1; | 258 params.weight = 1; |
| 255 mLayoutContainer.addView(layoutToShow, params); | 259 mLayoutContainer.addView(layoutToShow, params); |
| 256 } | 260 } |
| 257 } | 261 } |
| 258 } | 262 } |
| OLD | NEW |