Commit 56a12e68 authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[Modern] update some more icon colors to v2 Grey 800

+ Change color for icons from google_grey_600 to v2 Grey 800
+ Add custom attribute for tinting preference icons set from XML
+ Update icon color for Download spinner and location dialog

Bug: 834884, 863519
Change-Id: I7c9b61ad8983ef0fa01ad69065bdfe0b3baafa23
Reviewed-on: https://chromium-review.googlesource.com/1141128Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576124}
parent 013bfb76
......@@ -6,5 +6,5 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/white" android:state_selected="true"/>
<item android:color="@color/primary_text_disabled_material_light" android:state_enabled="false"/>
<item android:color="@color/google_grey_600"/>
<item android:color="@color/default_icon_color"/>
</selector>
......@@ -102,7 +102,7 @@
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/download_notification_pause_button"
android:src="@drawable/ic_pause_white_24dp"
app:chrometint="@color/google_grey_600" />
app:chrometint="@color/default_icon_color" />
<org.chromium.chrome.browser.widget.TintedImageButton
android:id="@+id/cancel_button"
......@@ -116,7 +116,7 @@
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/download_notification_cancel_button"
android:src="@drawable/btn_close"
app:chrometint="@color/google_grey_600" />
app:chrometint="@color/default_icon_color" />
</RelativeLayout>
</LinearLayout>
</view>
......@@ -32,7 +32,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_drive_file_24dp"
app:chrometint="@color/black_alpha_87"
app:chrometint="@color/default_icon_color"
style="@style/ListItemStartIcon" />
<org.chromium.chrome.browser.widget.AlertDialogEditText
......@@ -53,7 +53,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_folder_blue_24dp"
app:chrometint="@color/black_alpha_87"
app:chrometint="@color/default_icon_color"
style="@style/ListItemStartIcon" />
<Spinner
......
......@@ -82,7 +82,7 @@
android:layout_marginStart="4dp"
android:src="@drawable/offline_pin_round"
android:scaleType="centerInside"
android:tint="@color/black_alpha_65"
android:tint="@color/default_icon_color"
app:layout_column="2"
app:layout_row="2"
app:layout_columnSpan="2"
......
......@@ -47,7 +47,7 @@
android:layout_weight="0"
android:visibility="gone" />
<ImageView
<org.chromium.chrome.browser.widget.TintedImageView
android:id="@+id/expand_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -55,7 +55,8 @@
android:layout_gravity="center_vertical|end"
android:paddingEnd="16dp"
tools:ignore="ContentDescription"
android:src="@drawable/ic_expand_more_black_24dp" />
android:src="@drawable/ic_expand_more_black_24dp"
app:chrometint="@color/dark_mode_tint" />
</LinearLayout>
<TextView
......
......@@ -20,6 +20,11 @@
<attr name="helpContext" format="string" />
</declare-styleable>
<declare-styleable name="ChromeBasePreference">
<!-- The tint color for the icon set by android:icon. -->
<attr name="iconTint" format="color" />
</declare-styleable>
<declare-styleable name="ChromeSwitchPreference">
<!-- Prevents the summary text from being styled like title text in the
case that the title is empty. -->
......
......@@ -3,7 +3,10 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<org.chromium.chrome.browser.preferences.ChromeBasePreference
android:key="os_permissions_warning" />
<org.chromium.chrome.browser.preferences.ChromeBasePreference
......@@ -14,7 +17,8 @@
<org.chromium.chrome.browser.preferences.TextMessagePreference
android:key="intrusive_ads_info"
android:title="@string/intrusive_ads_information"
android:icon="@drawable/btn_info" />
android:icon="@drawable/btn_info"
app:iconTint="@color/default_icon_color" />
<Preference
android:key="intrusive_ads_info_divider"
android:layout="@layout/divider_preference" />
......
......@@ -4,13 +4,15 @@
found in the LICENSE file. -->
<!-- The order of the following items is from: http://crbug.com/610358. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- All sites -->
<org.chromium.chrome.browser.preferences.website.SiteSettingsPreference
android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences"
android:key="all_sites"
android:title="@string/all_sites"
android:icon="@drawable/settings_all_sites" />
android:icon="@drawable/settings_all_sites"
app:iconTint="@color/default_icon_color" />
<!-- Cookies -->
<org.chromium.chrome.browser.preferences.website.SiteSettingsPreference
android:key="cookies"
......@@ -64,7 +66,8 @@
android:fragment="org.chromium.chrome.browser.preferences.website.SiteSettingsPreferences"
android:key="media"
android:title="@string/media_permission_title"
android:icon="@drawable/settings_media" />
android:icon="@drawable/settings_media"
app:iconTint="@color/default_icon_color" />
<!-- Sound -->
<org.chromium.chrome.browser.preferences.website.SiteSettingsPreference
android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences"
......@@ -81,7 +84,8 @@
android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences"
android:key="use_storage"
android:title="@string/website_settings_storage"
android:icon="@drawable/settings_storage" />
android:icon="@drawable/settings_storage"
app:iconTint="@color/default_icon_color" />
<!-- USB -->
<org.chromium.chrome.browser.preferences.website.SiteSettingsPreference
android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences"
......
......@@ -243,7 +243,7 @@ public class DownloadManagerUi implements OnMenuItemClickListener, SearchDelegat
}
});
mFilterAdapter = new FilterAdapter();
mFilterAdapter = new FilterAdapter(mActivity.getResources());
mFilterAdapter.initialize(this);
boolean isLocationEnabled =
......
......@@ -4,8 +4,10 @@
package org.chromium.chrome.browser.download.ui;
import android.content.res.Resources;
import android.support.annotation.LayoutRes;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -19,8 +21,17 @@ import org.chromium.chrome.browser.util.FeatureUtilities;
/** An adapter that allows selecting an item from a dropdown spinner. */
class FilterAdapter extends BaseAdapter implements AdapterView.OnItemSelectedListener {
private final int mIconColor;
private DownloadManagerUi mManagerUi;
/**
* @param resources The {@link Resources} used to retrieve resources.
*/
FilterAdapter(Resources resources) {
super();
mIconColor = ApiCompatibilityUtils.getColor(resources, R.color.default_icon_color);
}
@Override
public int getCount() {
return DownloadFilter.getFilterCount();
......@@ -45,6 +56,7 @@ class FilterAdapter extends BaseAdapter implements AdapterView.OnItemSelectedLis
VectorDrawableCompat iconDrawable =
VectorDrawableCompat.create(mManagerUi.getActivity().getResources(), iconId,
mManagerUi.getActivity().getTheme());
DrawableCompat.setTint(iconDrawable, mIconColor);
labelView.setCompoundDrawablesWithIntrinsicBounds(iconDrawable, null, null, null);
return labelView;
......
......@@ -5,11 +5,17 @@
package org.chromium.chrome.browser.preferences;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import org.chromium.chrome.R;
/**
* A preference that supports some Chrome-specific customizations:
*
......@@ -18,15 +24,18 @@ import android.widget.TextView;
* enterprise icon, disables clicks, etc.
*
* 2. This preference can have a multiline title.
* 3. This preference can set an icon color in XML through app:iconTint. Note that if a
* ColorStateList is set, only the default color will be used.
*/
public class ChromeBasePreference extends Preference {
private ColorStateList mIconTint;
private ManagedPreferenceDelegate mManagedPrefDelegate;
/**
* Constructor for use in Java.
*/
public ChromeBasePreference(Context context) {
super(context);
this(context, null);
}
/**
......@@ -34,6 +43,10 @@ public class ChromeBasePreference extends Preference {
*/
public ChromeBasePreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ChromeBasePreference);
mIconTint = a.getColorStateList(R.styleable.ChromeBasePreference_iconTint);
a.recycle();
}
/**
......@@ -48,6 +61,10 @@ public class ChromeBasePreference extends Preference {
protected void onBindView(View view) {
super.onBindView(view);
((TextView) view.findViewById(android.R.id.title)).setSingleLine(false);
Drawable icon = getIcon();
if (icon != null && mIconTint != null) {
icon.setColorFilter(mIconTint.getDefaultColor(), PorterDuff.Mode.SRC_IN);
}
ManagedPreferencesUtils.onBindViewToPreference(mManagedPrefDelegate, this, view);
}
......
......@@ -4,12 +4,20 @@
package org.chromium.chrome.browser.preferences;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.StrictMode;
import android.preference.PreferenceFragment;
import android.support.annotation.DrawableRes;
import android.support.annotation.XmlRes;
import android.support.v7.content.res.AppCompatResources;
import android.view.View;
import android.view.ViewTreeObserver.OnScrollChangedListener;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
/**
* A helper class for Preferences.
*/
......@@ -50,4 +58,16 @@ public class PreferenceUtils {
}
};
}
/**
* Creates a {@link Drawable} for the given resource id with the default icon color applied.
*/
public static Drawable getTintedIcon(Context context, @DrawableRes int resId) {
Drawable icon = AppCompatResources.getDrawable(context, resId);
// DrawableCompat.setTint() doesn't work well on BitmapDrawables on older versions.
icon.setColorFilter(
ApiCompatibilityUtils.getColor(context.getResources(), R.color.default_icon_color),
PorterDuff.Mode.SRC_IN);
return icon;
}
}
......@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.preferences;
import android.content.Context;
import android.preference.Preference;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.view.View;
......@@ -14,8 +13,7 @@ import android.widget.TextView;
/**
* A preference that displays informational text.
*/
public class TextMessagePreference extends Preference {
public class TextMessagePreference extends ChromeBasePreference {
/**
* Constructor for inflating from XML.
*/
......
......@@ -8,13 +8,11 @@ import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.support.annotation.Nullable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -36,7 +34,6 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.PreferenceUtils;
import org.chromium.chrome.browser.preferences.SpinnerPreference;
import org.chromium.chrome.browser.preferences.privacy.BrowsingDataCounterBridge.BrowsingDataCounterCallback;
import org.chromium.chrome.browser.widget.TintedDrawable;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -58,7 +55,6 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
private static class Item implements BrowsingDataCounterCallback,
Preference.OnPreferenceClickListener {
private static final int MIN_DP_FOR_ICON = 360;
private final Context mContext;
private final ClearBrowsingDataPreferences mParent;
private final DialogOption mOption;
private final ClearBrowsingDataCheckBoxPreference mCheckbox;
......@@ -68,7 +64,6 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
public Item(Context context, ClearBrowsingDataPreferences parent, DialogOption option,
ClearBrowsingDataCheckBoxPreference checkbox, boolean selected, boolean enabled) {
super();
mContext = context;
mParent = parent;
mOption = option;
mCheckbox = checkbox;
......@@ -81,15 +76,7 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
int dp = mParent.getResources().getConfiguration().smallestScreenWidthDp;
if (dp >= MIN_DP_FOR_ICON) {
if (option.iconIsBitmap()) {
Drawable icon = TintedDrawable.constructTintedDrawable(
mContext, option.getIcon(), R.color.google_grey_600);
mCheckbox.setIcon(icon);
} else {
Drawable icon = VectorDrawableCompat.create(mParent.getResources(),
option.getIcon(), mParent.getActivity().getTheme());
mCheckbox.setIcon(icon);
}
mCheckbox.setIcon(PreferenceUtils.getTintedIcon(context, option.getIcon()));
}
}
......@@ -173,28 +160,25 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
* The various data types that can be cleared via this screen.
*/
public enum DialogOption {
CLEAR_HISTORY(BrowsingDataType.HISTORY, PREF_HISTORY, R.drawable.ic_watch_later_24dp, true),
CLEAR_HISTORY(BrowsingDataType.HISTORY, PREF_HISTORY, R.drawable.ic_watch_later_24dp),
CLEAR_COOKIES_AND_SITE_DATA(
BrowsingDataType.COOKIES, PREF_COOKIES, R.drawable.permission_cookie, true),
CLEAR_CACHE(BrowsingDataType.CACHE, PREF_CACHE, R.drawable.ic_collections_grey, false),
CLEAR_PASSWORDS(
BrowsingDataType.PASSWORDS, PREF_PASSWORDS, R.drawable.ic_vpn_key_grey, false),
CLEAR_FORM_DATA(BrowsingDataType.FORM_DATA, PREF_FORM_DATA, R.drawable.ic_edit_24dp, true),
BrowsingDataType.COOKIES, PREF_COOKIES, R.drawable.permission_cookie),
CLEAR_CACHE(BrowsingDataType.CACHE, PREF_CACHE, R.drawable.ic_collections_grey),
CLEAR_PASSWORDS(BrowsingDataType.PASSWORDS, PREF_PASSWORDS, R.drawable.ic_vpn_key_grey),
CLEAR_FORM_DATA(BrowsingDataType.FORM_DATA, PREF_FORM_DATA, R.drawable.ic_edit_24dp),
CLEAR_SITE_SETTINGS(BrowsingDataType.SITE_SETTINGS, PREF_SITE_SETTINGS,
R.drawable.ic_tv_options_input_settings_rotated_grey, false),
R.drawable.ic_tv_options_input_settings_rotated_grey),
CLEAR_MEDIA_LICENSES(BrowsingDataType.MEDIA_LICENSES, PREF_MEDIA_LICENSES,
R.drawable.permission_protected_media, true);
R.drawable.permission_protected_media);
private final int mDataType;
private final String mPreferenceKey;
private final int mIcon;
private final boolean mIsBitmap;
DialogOption(int dataType, String preferenceKey, int icon, boolean isBitmap) {
DialogOption(int dataType, String preferenceKey, int icon) {
mDataType = dataType;
mPreferenceKey = preferenceKey;
mIcon = icon;
mIsBitmap = isBitmap;
}
/**
......@@ -217,13 +201,6 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
public int getIcon() {
return mIcon;
}
/**
* @return Whether the icon is a bitmap. Otherwise it's a vector.
*/
public boolean iconIsBitmap() {
return mIsBitmap;
}
}
/**
......
......@@ -198,16 +198,6 @@ public class ContentSettingsResources {
return getResourceItem(contentType).getIcon();
}
/**
* Creates a {@link Drawable} for the given content type with the correct tint applied.
*/
public static Drawable getTintedIcon(int contentType, Resources resources) {
Drawable icon = ApiCompatibilityUtils.getDrawable(resources, getIcon(contentType));
icon.setColorFilter(ApiCompatibilityUtils.getColor(resources, R.color.default_icon_color),
PorterDuff.Mode.SRC_IN);
return icon;
}
/**
* Returns the Drawable object of the icon for a content type with a disabled tint.
*/
......
......@@ -608,7 +608,8 @@ public class SingleWebsitePreferences extends PreferenceFragment
preference.setIcon(category.getDisabledInAndroidIcon(getActivity()));
preference.setEnabled(false);
} else {
preference.setIcon(ContentSettingsResources.getTintedIcon(contentType, getResources()));
preference.setIcon(PreferenceUtils.getTintedIcon(
getActivity(), ContentSettingsResources.getIcon(contentType)));
}
}
......
......@@ -5,18 +5,18 @@
package org.chromium.chrome.browser.preferences.website;
import android.content.Context;
import android.preference.Preference;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.ChromeBasePreference;
/**
* A custom preference for drawing Site Settings entries.
*/
public class SiteSettingsPreference extends Preference {
public class SiteSettingsPreference extends ChromeBasePreference {
/**
* Constructor for inflating from XML.
*/
......
......@@ -207,7 +207,8 @@ public class SiteSettingsPreferences extends PreferenceFragment
}
if (p.isEnabled()) {
p.setIcon(ContentSettingsResources.getTintedIcon(contentType, getResources()));
p.setIcon(PreferenceUtils.getTintedIcon(
getActivity(), ContentSettingsResources.getIcon(contentType)));
} else {
p.setIcon(ContentSettingsResources.getDisabledIcon(contentType, getResources()));
}
......
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