OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.download.ui; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.text.format.Formatter; |
| 9 import android.util.AttributeSet; |
| 10 import android.view.View; |
| 11 import android.widget.FrameLayout; |
| 12 import android.widget.ImageView; |
| 13 import android.widget.TextView; |
| 14 |
| 15 import org.chromium.chrome.R; |
| 16 |
| 17 /** A header that presents users the option to view or hide the suggested offlin
e pages. */ |
| 18 public class OfflineGroupHeaderView extends FrameLayout { |
| 19 private TextView mPageCountHeader; |
| 20 private TextView mFileSizeView; |
| 21 private ImageView mImageView; |
| 22 |
| 23 private DownloadItemGroup mGroup; |
| 24 private DownloadHistoryAdapter mAdapter; |
| 25 |
| 26 public OfflineGroupHeaderView(Context context, AttributeSet attrs) { |
| 27 super(context, attrs); |
| 28 setOnClickListener(new View.OnClickListener() { |
| 29 @Override |
| 30 public void onClick(View v) { |
| 31 boolean currentState = mGroup.isSuggestedOfflinePagesSectionExpa
nded(); |
| 32 mAdapter.setSuggestedPagesHeaderState(mGroup, !currentState); |
| 33 mImageView.setImageResource( |
| 34 currentState ? R.drawable.ic_expanded : R.drawable.ic_co
llapsed); |
| 35 mImageView.setContentDescription(getResources().getString(curren
tState |
| 36 ? R.string.accessibility_collapse_offline_pages |
| 37 : R.string.accessibility_expand_offline_pages)); |
| 38 } |
| 39 }); |
| 40 } |
| 41 |
| 42 @Override |
| 43 protected void onFinishInflate() { |
| 44 super.onFinishInflate(); |
| 45 mPageCountHeader = (TextView) findViewById(R.id.page_count_text); |
| 46 mFileSizeView = (TextView) findViewById(R.id.filesize_view); |
| 47 mImageView = (ImageView) findViewById(R.id.expand_icon); |
| 48 } |
| 49 |
| 50 /** |
| 51 * @param adapter The adapter associated with this header. |
| 52 */ |
| 53 public void setAdapter(DownloadHistoryAdapter adapter) { |
| 54 mAdapter = adapter; |
| 55 } |
| 56 |
| 57 /** |
| 58 * Associates this header with a group. |
| 59 * @param group The group currently associated with this header. |
| 60 */ |
| 61 public void setGroup(DownloadItemGroup group) { |
| 62 mGroup = group; |
| 63 updateTitleText(group.getNumSuggestedOfflinePages()); |
| 64 mImageView.setImageResource(mGroup.isSuggestedOfflinePagesSectionExpande
d() |
| 65 ? R.drawable.ic_collapsed |
| 66 : R.drawable.ic_expanded); |
| 67 } |
| 68 |
| 69 private void updateTitleText(int pageCount) { |
| 70 mPageCountHeader.setText(getResources().getString( |
| 71 R.string.download_manager_offline_header_title, pageCount)); |
| 72 mFileSizeView.setText( |
| 73 Formatter.formatFileSize(getContext(), mGroup.getSuggestedOfflin
ePagesFileSize())); |
| 74 } |
| 75 } |
OLD | NEW |