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 if (mGroup.isSuggestedOfflinePagesSectionExpanded()) { | |
32 mAdapter.collapseSuggestedPagesHeader(mGroup); | |
33 mImageView.setImageResource(R.drawable.ic_expanded); | |
34 } else { | |
35 mAdapter.expandSuggestedPagesHeader(mGroup); | |
36 mImageView.setImageResource(R.drawable.ic_collapsed); | |
37 } | |
Theresa
2017/02/10 00:55:12
The expand icon should have a content description
shaktisahu
2017/02/11 00:39:06
Done.
| |
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 * Associates this view with the adapter and the corresponding group. | |
52 * @param group The group associated with this header. | |
53 * @param adapter The adapter associated with this header. | |
54 */ | |
55 public void bindGroupAndAdapter(DownloadItemGroup group, DownloadHistoryAdap ter adapter) { | |
56 mGroup = group; | |
57 mAdapter = adapter; | |
58 updateTitleText(group.getSuggestedOfflinePageCount()); | |
59 mImageView.setImageResource(mGroup.isSuggestedOfflinePagesSectionExpande d() | |
60 ? R.drawable.ic_collapsed | |
61 : R.drawable.ic_expanded); | |
62 } | |
63 | |
64 private void updateTitleText(int pageCount) { | |
65 mPageCountHeader.setText(getResources().getString( | |
66 R.string.download_manager_offline_header_title, pageCount)); | |
67 mFileSizeView.setText( | |
68 Formatter.formatFileSize(getContext(), mGroup.getSuggestedOfflin ePagesFileSize())); | |
69 } | |
70 } | |
OLD | NEW |