Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java |
| index 2a20979d222820d07b6ae3c81b115288c86364dd..cf15aac43e4c878ccbf4d9d7c0cd45a686bf0f43 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java |
| @@ -6,19 +6,32 @@ package org.chromium.chrome.browser.download.ui; |
| import android.app.Activity; |
| import android.content.Context; |
| +import android.content.res.Resources; |
| +import android.os.Environment; |
| +import android.os.StatFs; |
| import android.support.v4.view.GravityCompat; |
| import android.support.v4.widget.DrawerLayout; |
| import android.support.v7.app.ActionBarDrawerToggle; |
| import android.support.v7.widget.Toolbar; |
| import android.support.v7.widget.Toolbar.OnMenuItemClickListener; |
| +import android.text.format.Formatter; |
| import android.util.AttributeSet; |
| +import android.view.LayoutInflater; |
| import android.view.MenuItem; |
| import android.view.View; |
| +import android.view.ViewGroup; |
| +import android.widget.AdapterView; |
| +import android.widget.BaseAdapter; |
| +import android.widget.ImageView; |
| +import android.widget.ListView; |
| +import android.widget.ProgressBar; |
| +import android.widget.TextView; |
| import org.chromium.base.ApiCompatibilityUtils; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.widget.FadingShadow; |
| import org.chromium.chrome.browser.widget.FadingShadowView; |
| +import org.chromium.chrome.browser.widget.TintedDrawable; |
| import org.chromium.ui.base.DeviceFormFactor; |
| /** |
| @@ -32,12 +45,131 @@ public class DownloadManagerUi extends DrawerLayout { |
| void onCloseButtonClicked(DownloadManagerUi ui); |
| } |
| + /** Manages the display of space used by the downloads. */ |
| + private static final class SpaceDisplay { |
| + private TextView mSpaceUsedTextView; |
| + private TextView mSpaceTotalTextView; |
| + private ProgressBar mSpaceBar; |
| + |
| + SpaceDisplay(ViewGroup parent) { |
| + mSpaceUsedTextView = (TextView) parent.findViewById(R.id.space_used_display); |
| + mSpaceTotalTextView = (TextView) parent.findViewById(R.id.space_total_display); |
| + mSpaceBar = (ProgressBar) parent.findViewById(R.id.space_bar); |
| + } |
| + |
| + private void update(long usedBytes) { |
| + Context context = mSpaceUsedTextView.getContext(); |
| + |
| + // Display how big the storage is. |
| + StatFs statFs = new StatFs(Environment.getExternalStoragePublicDirectory( |
|
Ian Wen
2016/06/16 20:39:21
Move it to somewhere else so that we can make it c
gone
2016/06/21 18:23:02
Done.
|
| + Environment.DIRECTORY_DOWNLOADS).getPath()); |
| + long totalBlocks = ApiCompatibilityUtils.getBlockCount(statFs); |
| + long blockSize = ApiCompatibilityUtils.getBlockSize(statFs); |
| + long fileSystemBytes = totalBlocks * blockSize; |
| + String fileSystemReadable = Formatter.formatFileSize(context, fileSystemBytes); |
| + mSpaceTotalTextView.setText(context.getString( |
| + R.string.download_manager_ui_space_used, fileSystemReadable)); |
| + |
| + // Indicate how much space has been used by downloads. |
| + int percentage = (int) (100.0 * usedBytes / fileSystemBytes); |
|
Ian Wen
2016/06/16 20:39:21
Nit: maybe add a special case for fileSystemBytes
gone
2016/06/21 18:23:02
Done.
|
| + mSpaceBar.setProgress(percentage); |
| + mSpaceUsedTextView.setText(Formatter.formatFileSize(context, usedBytes)); |
| + } |
| + } |
| + |
| + /** Allows selecting an item from a list displayed in the drawer. */ |
| + private static final class FilterAdapter |
| + extends BaseAdapter implements AdapterView.OnItemClickListener { |
| + |
| + /** Icons and labels for each filter in the menu. */ |
| + private static final int[][] FILTER_INFO = new int[][] { |
|
Ian Wen
2016/06/16 20:39:21
INFO looks like it's not an array. How about FILTE
gone
2016/06/21 18:23:02
Done.
|
| + {R.drawable.ic_get_app_white, R.string.download_manager_ui_all_downloads}, |
| + {R.drawable.ic_drive_site_white, R.string.download_manager_ui_pages}, |
| + {R.drawable.ic_music_video_white, R.string.download_manager_ui_video}, |
| + {R.drawable.ic_music_note_white, R.string.download_manager_ui_audio}, |
| + {R.drawable.ic_image_white, R.string.download_manager_ui_images}, |
| + {R.drawable.ic_drive_file_white, R.string.download_manager_ui_documents}, |
| + {R.drawable.ic_folder_white, R.string.download_manager_ui_other} |
| + }; |
| + |
| + private final DrawerLayout mRootLayout; |
| + private final int mSelectedBackgroundColor; |
| + private int mSelectedIndex; |
|
Ian Wen
2016/06/16 20:39:21
Q: the first item is always selected by default, u
gone
2016/06/21 18:23:02
Not exactly in the spec, but "All downloads" seems
|
| + |
| + public FilterAdapter(DrawerLayout parent) { |
| + mRootLayout = parent; |
| + mSelectedBackgroundColor = ApiCompatibilityUtils.getColor( |
| + parent.getContext().getResources(), R.color.default_primary_color); |
| + } |
| + |
| + @Override |
| + public int getCount() { |
| + return FILTER_INFO.length; |
| + } |
| + |
| + @Override |
| + public Object getItem(int position) { |
| + return FILTER_INFO[position]; |
| + } |
| + |
| + @Override |
| + public long getItemId(int position) { |
| + return position; |
| + } |
| + |
| + @Override |
| + public View getView(int position, View convertView, ViewGroup parent) { |
| + Context context = mRootLayout.getContext(); |
| + Resources resources = context.getResources(); |
| + |
| + View view = convertView; |
| + if (view == null) { |
| + view = LayoutInflater.from(context).inflate( |
| + R.layout.download_manager_ui_drawer_filter, null); |
| + } |
| + |
| + ImageView iconView = ((ImageView) view.findViewById(R.id.icon)); |
| + int iconId = FILTER_INFO[position][0]; |
| + |
| + TextView labelView = ((TextView) view.findViewById(R.id.label)); |
| + labelView.setText(FILTER_INFO[position][1]); |
| + |
| + if (position == mSelectedIndex) { |
| + // Highlight the selected item by changing the foreground and background colors. |
| + view.setBackgroundColor(mSelectedBackgroundColor); |
| + iconView.setImageDrawable(TintedDrawable.constructTintedDrawable( |
| + resources, iconId, R.color.light_active_color)); |
| + labelView.setTextColor( |
| + ApiCompatibilityUtils.getColor(resources, R.color.light_active_color)); |
| + } else { |
| + // Draw the item normally. |
| + view.setBackground(null); |
| + iconView.setImageResource(iconId); |
| + labelView.setTextColor( |
| + ApiCompatibilityUtils.getColor(resources, R.color.default_text_color)); |
| + } |
| + |
| + return view; |
| + } |
| + |
| + @Override |
| + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| + mSelectedIndex = position; |
| + notifyDataSetChanged(); |
| + mRootLayout.closeDrawer(GravityCompat.START); |
| + } |
| + } |
| + |
| + private final FilterAdapter mFilterAdapter; |
| private DownloadManagerUiDelegate mDelegate; |
| private ActionBarDrawerToggle mActionBarDrawerToggle; |
| private DownloadManagerToolbar mToolbar; |
| + private SpaceDisplay mSpaceDisplay; |
| + private ListView mFilterView; |
| public DownloadManagerUi(Context context, AttributeSet attrs) { |
| super(context, attrs); |
| + mFilterAdapter = new FilterAdapter(this); |
| } |
| @Override |
| @@ -46,6 +178,11 @@ public class DownloadManagerUi extends DrawerLayout { |
| mToolbar = (DownloadManagerToolbar) findViewById(R.id.action_bar); |
| mToolbar.setOnMenuItemClickListener(createMenuItemClickListener()); |
| + |
| + mSpaceDisplay = new SpaceDisplay(this); |
| + mFilterView = (ListView) findViewById(R.id.section_list); |
| + mFilterView.setAdapter(mFilterAdapter); |
| + mFilterView.setOnItemClickListener(mFilterAdapter); |
| } |
| /** |
| @@ -84,6 +221,8 @@ public class DownloadManagerUi extends DrawerLayout { |
| R.color.bookmark_app_bar_shadow_color), FadingShadow.POSITION_TOP); |
| } |
| + mSpaceDisplay.update(0); |
| + |
| ((Toolbar) findViewById(R.id.action_bar)).setTitle(R.string.menu_downloads); |
| } |