Commit cb55d023 authored by David Trainor's avatar David Trainor Committed by Commit Bot

Polish download home chips

Move the download home chips closer to the proper spec values.  This
involves:
- Removing the icon from the chip.
- Updating the colors/layout to match the new design.
- Removing ChipView as it is no longer needed.

BUG=839489

Change-Id: Ibdf2d9912014ad3bd90ed37b5ec2aa970d0db630
Reviewed-on: https://chromium-review.googlesource.com/1088187
Commit-Queue: David Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565445}
parent 024a9c03
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/google_blue_50" android:state_selected="true" />
<item android:color="@android:color/white" android:state_enabled="true" />
<item android:color="@color/google_grey_100" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/google_grey_300"
android:state_enabled="true"
android:state_pressed="false"
android:state_selected="false" />
<item android:color="@android:color/transparent" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/google_blue_500" android:state_selected="true" />
<item android:color="@color/google_grey_600" android:state_enabled="true" />
<item android:color="@color/google_grey_400" />
</selector>
......@@ -4,10 +4,8 @@
found in the LICENSE file.
-->
<!-- TODO(crbug.com/839489): Update based on specs. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/google_grey_300" />
<stroke android:width="2dp" android:color="@color/google_blue_300" />
<corners android:radius="3dp" />
<padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" />
<solid android:color="@color/chip_background_color" />
<stroke android:width="1dp" android:color="@color/chip_stroke_color" />
<corners android:radius="8dp" />
</shape>
\ No newline at end of file
......@@ -4,17 +4,29 @@
found in the LICENSE file.
-->
<!-- TODO(crbug.com/839489): Update values based on specs. -->
<org.chromium.chrome.browser.download.home.filter.chips.ChipView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="32dp"
android:gravity="center"
android:maxLines="1"
android:paddingStart="13dp"
android:paddingEnd="13dp"
android:textAlignment="center"
android:clickable="true"
android:textAppearance="@style/BlueButtonText2"
android:background="@drawable/chip_bg" />
\ No newline at end of file
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@drawable/chip_bg">
<org.chromium.chrome.browser.widget.TintedImageView
android:id="@+id/icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="8dp"
android:gravity="center"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:paddingStart="@dimen/chip_icon_padding"
android:paddingEnd="@dimen/chip_no_icon_padding"
android:textAlignment="center"
android:textAppearance="@style/DownloadHomeChipText" />
</LinearLayout>
......@@ -636,6 +636,10 @@
</style>
<!-- Download Home -->
<style name="DownloadHomeChipText">
<item name="android:textColor">@color/chip_text_color</item>
<item name="android:textSize">@dimen/text_size_medium</item>
</style>
<style name="DownloadHomeStatusText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
......
......@@ -568,6 +568,8 @@
<item type="dimen" name="dialog_fixed_height_minor">100%</item>
<!-- Chip list dimensions -->
<dimen name="chip_no_icon_padding">16dp</dimen>
<dimen name="chip_icon_padding">4dp</dimen>
<dimen name="chip_list_padding">2.5dp</dimen>
<!-- Download manager dimensions -->
......
......@@ -45,24 +45,27 @@ public class FilterChipsProvider implements ChipsProvider, OfflineItemFilterObse
mSource = source;
Chip noneChip = new Chip(Filters.NONE, R.string.download_manager_ui_all_downloads,
R.string.download_manager_ui_all_downloads, R.drawable.ic_play_arrow_white_24dp,
R.string.download_manager_ui_all_downloads, Chip.INVALID_ICON_ID,
() -> onChipSelected(Filters.NONE));
Chip videosChip = new Chip(Filters.VIDEOS, R.string.download_manager_ui_video,
R.string.download_manager_ui_video, R.drawable.ic_play_arrow_white_24dp,
R.string.download_manager_ui_video, R.drawable.ic_videocam_24dp,
() -> onChipSelected(Filters.VIDEOS));
Chip musicChip = new Chip(Filters.MUSIC, R.string.download_manager_ui_audio,
R.string.download_manager_ui_audio, R.drawable.ic_play_arrow_white_24dp,
R.string.download_manager_ui_audio, R.drawable.ic_music_note_24dp,
() -> onChipSelected(Filters.MUSIC));
Chip imagesChip = new Chip(Filters.IMAGES, R.string.download_manager_ui_images,
R.string.download_manager_ui_images, R.drawable.ic_play_arrow_white_24dp,
R.string.download_manager_ui_images, R.drawable.ic_drive_image_24dp,
() -> onChipSelected(Filters.IMAGES));
Chip sitesChip = new Chip(Filters.SITES, R.string.download_manager_ui_pages,
R.string.download_manager_ui_pages, R.drawable.ic_play_arrow_white_24dp,
R.string.download_manager_ui_pages, R.drawable.ic_globe_24dp,
() -> onChipSelected(Filters.SITES));
Chip otherChip = new Chip(Filters.OTHER, R.string.download_manager_ui_other,
R.string.download_manager_ui_other, R.drawable.ic_play_arrow_white_24dp,
R.string.download_manager_ui_other, R.drawable.ic_drive_file_24dp,
() -> onChipSelected(Filters.OTHER));
// By default select the none chip.
noneChip.selected = true;
mSortedChips.add(noneChip);
mSortedChips.add(videosChip);
mSortedChips.add(musicChip);
......
......@@ -12,6 +12,9 @@ import android.support.annotation.StringRes;
* and enable states are not.
*/
public class Chip {
/** An id to use for {@link #icon} when there is no icon on the chip. */
public static final int INVALID_ICON_ID = -1;
/** An id used to identify this chip. */
public final int id;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.download.home.filter.chips;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import org.chromium.base.ApiCompatibilityUtils;
/**
* A {@link AppCompatTextView} that visually represents a {@link Chip} in a chip list. The way to
* get a properly set up {@link ChipView} with the proper properties would be to inflate
* R.layout.chip.
*/
public class ChipView extends AppCompatTextView {
public ChipView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* Used to effectively set the start compound drawable on the {@link TextView}. Currently there
* is no compat method to handle setting the {@link ColorStateList} for compound drawables.
* @param icon The drawable id that represents the icon to use in the chip.
*/
public void setChipIcon(@DrawableRes int icon) {
Drawable drawable =
DrawableCompat.wrap(ApiCompatibilityUtils.getDrawable(getResources(), icon));
ColorStateList textColor = getTextColors();
if (textColor != null) DrawableCompat.setTintList(drawable.mutate(), textColor);
ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(
this, drawable, null, null, null);
}
}
\ No newline at end of file
......@@ -4,44 +4,72 @@
package org.chromium.chrome.browser.download.home.filter.chips;
import android.content.res.ColorStateList;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.modelutil.RecyclerViewAdapter.ViewBinder;
import org.chromium.chrome.browser.modelutil.SimpleListObservable;
import org.chromium.chrome.browser.widget.TintedImageView;
/** Responsible for binding the {@link ChipsModel} to {@link ViewHolder}s in the RecyclerView. */
class ChipsViewBinder
implements ViewBinder<SimpleListObservable<Chip>, ChipsViewBinder.ChipsViewHolder> {
/** The {@link ViewHolder} responsible for reflecting a {@link Chip} to a {@link ChipView}. */
/** The {@link ViewHolder} responsible for reflecting a {@link Chip} to a {@link View}. */
public static class ChipsViewHolder extends ViewHolder {
/**
* Builds a ChipsViewHolder around a specific {@link ChipView}.
* @param itemView
*/
private final int mTextStartPaddingWithIconPx;
private final int mTextStartPaddingWithNoIconPx;
private final TextView mText;
private final TintedImageView mImage;
/** Builds a ChipsViewHolder around a specific {@link View}. */
public ChipsViewHolder(View itemView) {
super(itemView);
assert itemView instanceof ChipView;
mText = (TextView) itemView.findViewById(R.id.text);
mImage = (TintedImageView) itemView.findViewById(R.id.icon);
ColorStateList textColors = mText.getTextColors();
if (textColors != null) mImage.setTint(textColors);
mTextStartPaddingWithIconPx =
mText.getResources().getDimensionPixelSize(R.dimen.chip_icon_padding);
mTextStartPaddingWithNoIconPx =
mText.getResources().getDimensionPixelSize(R.dimen.chip_no_icon_padding);
}
/**
* Pushes the properties of {@code chip} to {@code itemView}.
* @param chip The {@link Chip} to visually reflect in the stored {@link ChipView}.
* @param chip The {@link Chip} to visually reflect in the stored {@link View}.
*/
public void bind(Chip chip) {
ChipView view = (ChipView) itemView;
itemView.setEnabled(chip.enabled);
mText.setEnabled(chip.enabled);
mImage.setEnabled(chip.enabled);
itemView.setSelected(chip.selected);
itemView.setOnClickListener(v -> chip.chipSelectedListener.run());
mText.setContentDescription(mText.getContext().getText(chip.contentDescription));
mText.setText(chip.text);
view.setEnabled(chip.enabled);
view.setSelected(chip.selected);
view.setOnClickListener(v -> chip.chipSelectedListener.run());
int textStartPadding = mTextStartPaddingWithIconPx;
if (chip.icon == Chip.INVALID_ICON_ID) {
mImage.setVisibility(ViewGroup.GONE);
textStartPadding = mTextStartPaddingWithNoIconPx;
} else {
textStartPadding = mTextStartPaddingWithIconPx;
mImage.setVisibility(ViewGroup.VISIBLE);
mImage.setImageResource(chip.icon);
}
view.setChipIcon(chip.icon);
view.setText(chip.text);
view.setContentDescription(view.getContext().getText(chip.contentDescription));
ApiCompatibilityUtils.setPaddingRelative(mText, textStartPadding, mText.getPaddingTop(),
ApiCompatibilityUtils.getPaddingEnd(mText), mText.getPaddingBottom());
}
}
......
......@@ -446,7 +446,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/download/home/filter/chips/ChipsCoordinator.java",
"java/src/org/chromium/chrome/browser/download/home/filter/chips/ChipsProvider.java",
"java/src/org/chromium/chrome/browser/download/home/filter/chips/ChipsViewBinder.java",
"java/src/org/chromium/chrome/browser/download/home/filter/chips/ChipView.java",
"java/src/org/chromium/chrome/browser/download/home/glue/DownloadGlue.java",
"java/src/org/chromium/chrome/browser/download/home/glue/OfflineContentProviderGlue.java",
"java/src/org/chromium/chrome/browser/download/home/glue/ThumbnailRequestGlue.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment