Commit d705a3ef authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[Snowflake] Add presubmit checks for restricting Android text attributes

Add presubmit checks to detect Android text attributes defined outside
text appearance style, and text appearance style must be prefixed by
"TextAppearance.".

Bug: 775198, 819142
Change-Id: I3492b8845bb6c0bf46debf242e90defb8a532010
Reviewed-on: https://chromium-review.googlesource.com/1152424
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580923}
parent e4378cb9
...@@ -11,20 +11,26 @@ This presubmit checks for the following: ...@@ -11,20 +11,26 @@ This presubmit checks for the following:
- Colors are defined as RRGGBB or AARRGGBB - Colors are defined as RRGGBB or AARRGGBB
- No (A)RGB values are referenced outside colors.xml - No (A)RGB values are referenced outside colors.xml
- No duplicate (A)RGB values are referenced in colors.xml - No duplicate (A)RGB values are referenced in colors.xml
- XML namspace "app" is used for "http://schemas.android.com/apk/res-auto"
- Android text attributes are only defined in text appearance styles
""" """
from collections import defaultdict from collections import defaultdict
import re import re
import xml.etree.ElementTree as ET
COLOR_PATTERN = re.compile(r'(>|")(#[0-9A-Fa-f]+)(<|")') COLOR_PATTERN = re.compile(r'(>|")(#[0-9A-Fa-f]+)(<|")')
VALID_COLOR_PATTERN = re.compile( VALID_COLOR_PATTERN = re.compile(
r'^#([0-9A-F][0-9A-E]|[0-9A-E][0-9A-F])?[0-9A-F]{6}$') r'^#([0-9A-F][0-9A-E]|[0-9A-E][0-9A-F])?[0-9A-F]{6}$')
XML_APP_NAMESPACE_PATTERN = re.compile( XML_APP_NAMESPACE_PATTERN = re.compile(
r'xmlns:(\w+)="http://schemas.android.com/apk/res-auto"') r'xmlns:(\w+)="http://schemas.android.com/apk/res-auto"')
TEXT_APPEARANCE_STYLE_PATTERN = re.compile(r'^TextAppearance\.')
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
return _CommonChecks(input_api, output_api) result = _CommonChecks(input_api, output_api)
result.extend(_CheckNewTextAppearance(input_api, output_api))
return result
def CheckChangeOnCommit(input_api, output_api): def CheckChangeOnCommit(input_api, output_api):
...@@ -38,6 +44,7 @@ def _CommonChecks(input_api, output_api): ...@@ -38,6 +44,7 @@ def _CommonChecks(input_api, output_api):
result.extend(_CheckColorReferences(input_api, output_api)) result.extend(_CheckColorReferences(input_api, output_api))
result.extend(_CheckDuplicateColors(input_api, output_api)) result.extend(_CheckDuplicateColors(input_api, output_api))
result.extend(_CheckXmlNamespacePrefixes(input_api, output_api)) result.extend(_CheckXmlNamespacePrefixes(input_api, output_api))
result.extend(_CheckTextAppearance(input_api, output_api))
# Add more checks here # Add more checks here
return result return result
...@@ -167,3 +174,106 @@ def _CheckXmlNamespacePrefixes(input_api, output_api): ...@@ -167,3 +174,106 @@ def _CheckXmlNamespacePrefixes(input_api, output_api):
''', ''',
errors)] errors)]
return [] return []
def _CheckTextAppearance(input_api, output_api):
"""Checks text attributes are only used for text appearance styles in XMLs."""
text_attributes = [
'android:textColor', 'android:textSize', 'android:textStyle',
'android:fontFamily', 'android:textAllCaps']
namespace = {'android': 'http://schemas.android.com/apk/res/android'}
errors = []
for f in input_api.AffectedFiles(include_deletes=False):
if not f.LocalPath().endswith('.xml'):
continue
root = ET.fromstring(input_api.ReadFile(f))
# Check if there are text attributes defined outside text appearances.
for attribute in text_attributes:
# Get style name that contains text attributes but is not text appearance.
invalid_styles = []
for style in root.findall('style') + root.findall('.//style'):
name = style.get('name')
is_text_appearance = TEXT_APPEARANCE_STYLE_PATTERN.search(name)
item = style.find(".//item[@name='"+attribute+"']")
if is_text_appearance is None and item is not None:
invalid_styles.append(name)
# Append error messages.
contents = input_api.ReadFile(f)
style_count = 0
widget_count = len(root.findall('[@'+attribute+']', namespace)) + len(
root.findall('.//*[@'+attribute+']', namespace))
for line_number, line in enumerate(contents.splitlines(False)):
# Error for text attributes in non-text-appearance style.
if (style_count < len(invalid_styles) and
invalid_styles[style_count] in line):
errors.append(' %s:%d contains attribute %s\n \t%s' % (
f.LocalPath(), line_number+1, attribute, line.strip()))
style_count += 1
# Error for text attributes in layout.
if widget_count > 0 and attribute in line:
errors.append(' %s:%d contains attribute %s\n \t%s' % (
f.LocalPath(), line_number+1, attribute, line.strip()))
widget_count -= 1
# TODO(huayinz): Change the path on the error message to the corresponding
# styles.xml when this check applies to all resource directories.
if errors:
return [output_api.PresubmitError(
'''
Android Text Appearance Check failed:
Your modified files contain Android text attributes defined outside
text appearance styles, listed below.
It is recommended to use the pre-defined text appearance styles in
src/ui/android/java/res/values-v17/styles.xml
And to use
android:textAppearance="@style/SomeTextAppearance"
in the XML layout whenever possible.
If your text appearance absolutely has to deviate from the existing
pre-defined text appearance style, you will need UX approval for adding a
new text appearance style.
If your approved text appearance style is a common text appreance style,
please define it in src/ui/android/java/res/values-v17/styles.xml.
Otherwise, if your approved text appearance is feature-specific, in
chrome/android/java/res/values*/styles.xml, please define
<style name="TextAppearance.YourTextAppearanceName>
<item name="android:textColor">...</item>
<item name="android:textSize">...</item>
...
</style>
Please contact hannahs@chromium.org for UX approval, and
src/chrome/android/java/res/OWNERS for questions.
See https://crbug.com/775198 for more information.
''',
errors)]
return []
def _CheckNewTextAppearance(input_api, output_api):
"""Checks whether a new text appearance style is defined."""
errors = []
for f in input_api.AffectedFiles(include_deletes=False):
if not f.LocalPath().endswith('.xml'):
continue
for line_number, line in f.ChangedContents():
if '<style name="TextAppearance.' in line:
errors.append(
' %s:%d\n \t%s' % (f.LocalPath(), line_number, line.strip()))
if errors:
return [output_api.PresubmitPromptWarning(
'''
New Text Appearance in styles.xml Check failed:
Your new code added, edited or removed a text appearance style.
If you are removing or editing an existing text appearance style, or your
new text appearance style is approved by UX, please bypass this check.
Otherwise, please contact hannahs@chromium.org for UX approval, and
src/chrome/android/java/res/OWNERS for questions.
See https://crbug.com/775198 for more information.
''',
errors)]
return []
\ No newline at end of file
...@@ -147,5 +147,148 @@ class XmlNamespacePrefixesTest(unittest.TestCase): ...@@ -147,5 +147,148 @@ class XmlNamespacePrefixesTest(unittest.TestCase):
self.assertEqual(0, len(errors)) self.assertEqual(0, len(errors))
class TextAppearanceTest(unittest.TestCase):
def testFailure_Style(self):
lines = [
'<resource>',
'<style name="TestTextAppearance">',
'<item name="android:textColor">@color/default_text_color_link</item>',
'<item name="android:textSize">14sp</item>',
'<item name="android:textStyle">bold</item>',
'<item name="android:fontFamily">some-font</item>',
'<item name="android:textAllCaps">true</item>',
'</style>',
'</resource>']
mock_input_api = MockInputApi()
mock_input_api.files = [MockFile('chrome/path/test.xml', lines)]
errors = PRESUBMIT._CheckTextAppearance(mock_input_api, MockOutputApi())
self.assertEqual(1, len(errors))
self.assertEqual(5, len(errors[0].items))
self.assertEqual(
' chrome/path/test.xml:2 contains attribute android:textColor',
errors[0].items[0].splitlines()[0])
self.assertEqual(
' chrome/path/test.xml:2 contains attribute android:textSize',
errors[0].items[1].splitlines()[0])
self.assertEqual(
' chrome/path/test.xml:2 contains attribute android:textStyle',
errors[0].items[2].splitlines()[0])
self.assertEqual(
' chrome/path/test.xml:2 contains attribute android:fontFamily',
errors[0].items[3].splitlines()[0])
self.assertEqual(
' chrome/path/test.xml:2 contains attribute android:textAllCaps',
errors[0].items[4].splitlines()[0])
def testSuccess_Style(self):
lines = [
'<resource>',
'<style name="TextAppearance.Test">',
'<item name="android:textColor">@color/default_text_color_link</item>',
'<item name="android:textSize">14sp</item>',
'<item name="android:textStyle">bold</item>',
'<item name="android:fontFamily">some-font</item>',
'<item name="android:textAllCaps">true</item>',
'</style>',
'<style name="TestStyle">',
'<item name="android:background">some_background</item>',
'</style>',
'</resource>']
mock_input_api = MockInputApi()
mock_input_api.files = [MockFile('chrome/path/test.xml', lines)]
errors = PRESUBMIT._CheckTextAppearance(mock_input_api, MockOutputApi())
self.assertEqual(0, len(errors))
def testFailure_Widget(self):
lines_top_level = [
'<TextView',
'xmlns:android="http://schemas.android.com/apk/res/android"',
'android:layout_width="match_parent"',
'android:layout_height="@dimen/snippets_article_header_height"',
'android:textColor="@color/snippets_list_header_text_color"',
'android:textSize="14sp" />']
lines_subcomponent_widget = [
'<RelativeLayout',
'xmlns:android="http://schemas.android.com/apk/res/android"',
'android:layout_width="match_parent"',
'android:layout_height="wrap_content">',
'<View',
'android:textColor="@color/error_text_color"',
'android:textSize="@dimen/text_size_medium"',
'android:textAllCaps="true"',
'android:background="@drawable/infobar_shadow_top"',
'android:visibility="gone" />',
'</RelativeLayout>']
mock_input_api = MockInputApi()
mock_input_api.files = [
MockFile('chrome/path/test1.xml', lines_top_level),
MockFile('chrome/path/test2.xml', lines_subcomponent_widget)]
errors = PRESUBMIT._CheckTextAppearance(mock_input_api, MockOutputApi())
self.assertEqual(1, len(errors))
self.assertEqual(5, len(errors[0].items))
self.assertEqual(
' chrome/path/test1.xml:5 contains attribute android:textColor',
errors[0].items[0].splitlines()[0])
self.assertEqual(
' chrome/path/test1.xml:6 contains attribute android:textSize',
errors[0].items[1].splitlines()[0])
self.assertEqual(
' chrome/path/test2.xml:6 contains attribute android:textColor',
errors[0].items[2].splitlines()[0])
self.assertEqual(
' chrome/path/test2.xml:7 contains attribute android:textSize',
errors[0].items[3].splitlines()[0])
self.assertEqual(
' chrome/path/test2.xml:8 contains attribute android:textAllCaps',
errors[0].items[4].splitlines()[0])
def testSuccess_Widget(self):
lines = [
'<RelativeLayout',
'xmlns:android="http://schemas.android.com/apk/res/android"',
'android:layout_width="match_parent"',
'android:layout_height="wrap_content">',
'<View',
'android:background="@drawable/infobar_shadow_top"',
'android:visibility="gone" />',
'</RelativeLayout>']
mock_input_api = MockInputApi()
mock_input_api.files = [MockFile('chrome/path/test.xml', lines)]
errors = PRESUBMIT._CheckTextAppearance(mock_input_api, MockOutputApi())
self.assertEqual(0, len(errors))
class NewTextAppearanceTest(unittest.TestCase):
def testFailure(self):
lines = [
'<resource>',
'<style name="TextAppearance.Test">',
'<item name="android:textColor">@color/default_text_color_link</item>',
'<item name="android:textSize">14sp</item>',
'</style>',
'</resource>']
mock_input_api = MockInputApi()
mock_input_api.files = [MockFile('chrome/path/test.xml', lines)]
errors = PRESUBMIT._CheckNewTextAppearance(mock_input_api, MockOutputApi())
self.assertEqual(1, len(errors))
self.assertEqual(1, len(errors[0].items))
self.assertEqual(
' chrome/path/test.xml:2',
errors[0].items[0].splitlines()[0])
def testSuccess(self):
lines = [
'<resource>',
'<style name="TextAppearanceTest">',
'<item name="android:textColor">@color/default_text_color_link</item>',
'<item name="android:textSize">14sp</item>',
'</style>',
'</resource>']
mock_input_api = MockInputApi()
mock_input_api.files = [MockFile('chrome/path/test.xml', lines)]
errors = PRESUBMIT._CheckNewTextAppearance(mock_input_api, MockOutputApi())
self.assertEqual(0, len(errors))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
android:layout_marginStart="@dimen/pref_autofill_field_horizontal_padding" android:layout_marginStart="@dimen/pref_autofill_field_horizontal_padding"
android:layout_marginEnd="@dimen/pref_autofill_field_horizontal_padding" android:layout_marginEnd="@dimen/pref_autofill_field_horizontal_padding"
android:labelFor="@+id/autofill_credit_card_editor_billing_address_spinner" android:labelFor="@+id/autofill_credit_card_editor_billing_address_spinner"
android:textAppearance="@style/PreferenceFloatLabelTextAppearance" android:textAppearance="@style/BlackCaption"
android:text="@string/autofill_credit_card_editor_billing_address" /> android:text="@string/autofill_credit_card_editor_billing_address" />
<android.support.v7.widget.AppCompatSpinner <android.support.v7.widget.AppCompatSpinner
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
android:layout_marginTop="@dimen/pref_autofill_field_top_margin" android:layout_marginTop="@dimen/pref_autofill_field_top_margin"
android:layout_marginStart="@dimen/pref_autofill_field_horizontal_padding" android:layout_marginStart="@dimen/pref_autofill_field_horizontal_padding"
android:layout_marginEnd="@dimen/pref_autofill_field_horizontal_padding" android:layout_marginEnd="@dimen/pref_autofill_field_horizontal_padding"
android:textAppearance="@style/PreferenceFloatLabelTextAppearance" android:textAppearance="@style/BlackCaption"
android:text="@string/autofill_credit_card_editor_expiration_date" /> android:text="@string/autofill_credit_card_editor_expiration_date" />
<LinearLayout <LinearLayout
......
...@@ -30,5 +30,5 @@ ...@@ -30,5 +30,5 @@
android:paddingStart="@dimen/chip_icon_padding" android:paddingStart="@dimen/chip_icon_padding"
android:paddingEnd="@dimen/chip_no_icon_padding" android:paddingEnd="@dimen/chip_no_icon_padding"
android:textAlignment="center" android:textAlignment="center"
android:textAppearance="@style/DownloadHomeChipText" /> android:textAppearance="@style/TextAppearance.DownloadHomeChip" />
</LinearLayout> </LinearLayout>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
android:paddingBottom="7dip" android:paddingBottom="7dip"
android:paddingStart="24dp" android:paddingStart="24dp"
android:paddingEnd="15dp" android:paddingEnd="15dp"
style="@style/PreferenceTextAppearanceMedium" android:textAppearance="@style/TextAppearance.PreferenceMediumText"
android:text="@string/clear_browsing_data_important_dialog_text"/> android:text="@string/clear_browsing_data_important_dialog_text"/>
<ListView <ListView
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
found in the LICENSE file. --> found in the LICENSE file. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/data_reduction_stats_container" android:id="@+id/data_reduction_stats_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -31,8 +30,7 @@ ...@@ -31,8 +30,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/default_text_color_link" android:textAppearance="@style/TextAppearance.DataReductionHeadline" />
android:textSize="23sp" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -77,15 +75,13 @@ ...@@ -77,15 +75,13 @@
android:id="@+id/data_reduction_start_date" android:id="@+id/data_reduction_start_date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/PreferenceSummary" android:textAppearance="@style/BlackBody" />
android:textSize="14sp" />
<TextView <TextView
android:id="@+id/data_reduction_end_date" android:id="@+id/data_reduction_end_date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/PreferenceSummary" android:textAppearance="@style/BlackBody" />
android:textSize="14sp" />
</FrameLayout> </FrameLayout>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
android:id="@+id/label" android:id="@+id/label"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/PreferenceFloatLabelTextAppearance" /> android:textAppearance="@style/BlackCaption" />
<org.chromium.chrome.browser.widget.prefeditor.ExpandableGridView <org.chromium.chrome.browser.widget.prefeditor.ExpandableGridView
android:id="@+id/icons_container" android:id="@+id/icons_container"
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:text="@string/learn_more" android:text="@string/learn_more"
android:textAppearance="@style/BlueButtonText1" android:textAppearance="@style/TextAppearance.IncognitoNewTabLearnMoreLinkModern"
android:lineSpacingExtra="@dimen/md_incognito_ntp_line_spacing" /> android:lineSpacingExtra="@dimen/md_incognito_ntp_line_spacing" />
</LinearLayout> </LinearLayout>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
android:id="@+id/spinner_label" android:id="@+id/spinner_label"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/PreferenceFloatLabelTextAppearance" /> android:textAppearance="@style/BlackCaption" />
<android.support.v7.widget.AppCompatSpinner <android.support.v7.widget.AppCompatSpinner
android:id="@+id/spinner" android:id="@+id/spinner"
......
...@@ -45,6 +45,6 @@ ...@@ -45,6 +45,6 @@
android:layout_below="@id/mid_label" android:layout_below="@id/mid_label"
android:layout_toStartOf="@id/icon" android:layout_toStartOf="@id/icon"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:textAppearance="@style/PreferenceFloatLabelTextAppearance" /> android:textAppearance="@style/BlackCaption" />
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="1" android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/PreferenceCategoryTextStyle" /> android:textAppearance="@style/TextAppearance.PreferenceCategoryText" />
<!-- Users of this layout are responsible to set contentDescription. --> <!-- Users of this layout are responsible to set contentDescription. -->
<ImageView <ImageView
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<item name="android:alertDialogTheme">@style/PreferencesDialogTheme</item> <item name="android:alertDialogTheme">@style/PreferencesDialogTheme</item>
<item name="android:divider">@null</item> <item name="android:divider">@null</item>
<item name="android:spinnerItemStyle">@style/PreferenceSpinnerItem</item> <item name="android:spinnerItemStyle">@style/PreferenceSpinnerItem</item>
<item name="floatLabelTextAppearance">@style/PreferenceFloatLabelTextAppearance</item> <item name="floatLabelTextAppearance">@style/BlackCaption</item>
<item name="floatLabelPaddingLeft">@dimen/pref_autofill_field_horizontal_padding</item> <item name="floatLabelPaddingLeft">@dimen/pref_autofill_field_horizontal_padding</item>
<item name="floatLabelPaddingRight">@dimen/pref_autofill_field_horizontal_padding</item> <item name="floatLabelPaddingRight">@dimen/pref_autofill_field_horizontal_padding</item>
<item name="floatLabelPaddingTop">@dimen/pref_autofill_field_top_margin</item> <item name="floatLabelPaddingTop">@dimen/pref_autofill_field_top_margin</item>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<item name="android:paddingStart">?android:attr/listPreferredItemPaddingStart</item> <item name="android:paddingStart">?android:attr/listPreferredItemPaddingStart</item>
<item name="android:paddingEnd">4dp</item> <item name="android:paddingEnd">4dp</item>
</style> </style>
<style name="PreferenceCategoryTextStyle" parent="RobotoMediumStyle"> <style name="TextAppearance.PreferenceCategoryText" parent="RobotoMediumStyle">
<item name="android:textColor">@color/pref_accent_color</item> <item name="android:textColor">@color/pref_accent_color</item>
<item name="android:textSize">12sp</item> <item name="android:textSize">12sp</item>
</style> </style>
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
<item name="android:textAppearance">?android:attr/textAppearanceListItem</item> <item name="android:textAppearance">?android:attr/textAppearanceListItem</item>
</style> </style>
<style name="PreferenceSummary"> <style name="PreferenceSummary">
<item name="android:textAppearance">?android:attr/textAppearanceListItemSecondary</item> <item name="android:textAppearance">@style/BlackBody</item>
<item name="android:textColor">?android:attr/textColorSecondary</item>
</style> </style>
<style name="PreferenceLayoutBase"> <style name="PreferenceLayoutBase">
<item name="android:background">?android:attr/activatedBackgroundIndicator</item> <item name="android:background">?android:attr/activatedBackgroundIndicator</item>
...@@ -67,6 +66,10 @@ ...@@ -67,6 +66,10 @@
<style name="WebNotificationButton" <style name="WebNotificationButton"
parent="@android:style/Widget.DeviceDefault.Light.Button.Borderless.Small"> parent="@android:style/Widget.DeviceDefault.Light.Button.Borderless.Small">
<item name="android:background">@drawable/web_notification_button_background</item> <item name="android:background">@drawable/web_notification_button_background</item>
<item name="android:textAppearance">@style/TextAppearance.WebNotificationButton</item>
</style>
<style name="TextAppearance.WebNotificationButton"
parent="android:TextAppearance.DeviceDefault.Widget.Button">
<item name="android:textColor">@color/secondary_text_default_material_light</item> <item name="android:textColor">@color/secondary_text_default_material_light</item>
</style> </style>
<style name="WebNotificationSettingsButton" <style name="WebNotificationSettingsButton"
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<color name="input_underline_error_color">#D32F2F</color> <color name="input_underline_error_color">#D32F2F</color>
<color name="explanation_text_color">#909090</color> <color name="explanation_text_color">#909090</color>
<color name="text_highlight_color">#C6DAFC</color> <color name="text_highlight_color">#C6DAFC</color>
<!--TODO(huayinz): Change descriptive_text_color to the new default_text_color_secondary. -->
<color name="descriptive_text_color">#646464</color> <color name="descriptive_text_color">#646464</color>
<color name="error_text_color">@color/google_red_700</color> <color name="error_text_color">@color/google_red_700</color>
...@@ -122,9 +123,6 @@ ...@@ -122,9 +123,6 @@
<color name="signin_body_background">@color/google_grey_50</color> <color name="signin_body_background">@color/google_grey_50</color>
<color name="signin_header_animation_background">#F8F9FA</color> <color name="signin_header_animation_background">#F8F9FA</color>
<!-- Sad Tab colors -->
<color name="sad_tab_body_text_color">#646464</color>
<!-- NTP and Home sheet colors. Also used on the bookmarks and recent tabs pages. --> <!-- NTP and Home sheet colors. Also used on the bookmarks and recent tabs pages. -->
<color name="ntp_bg">@color/default_primary_color</color> <color name="ntp_bg">@color/default_primary_color</color>
<color name="ntp_bg_incognito">@color/incognito_modern_primary_color</color> <color name="ntp_bg_incognito">@color/incognito_modern_primary_color</color>
......
...@@ -627,9 +627,10 @@ public abstract class PaymentRequestSection extends LinearLayout implements View ...@@ -627,9 +627,10 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
LineItem item = cart.getContents().get(i); LineItem item = cart.getContents().get(i);
TextView description = new TextView(context); TextView description = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending() ApiCompatibilityUtils.setTextAppearance(description,
? R.style.PaymentsUiSectionPendingTextEndAligned item.getIsPending()
: R.style.PaymentsUiSectionDescriptiveTextEndAligned); ? R.style.TextAppearance_PaymentsUiSectionPendingTextEndAligned
: R.style.TextAppearance_PaymentsUiSectionDescriptiveTextEndAligned);
description.setText(item.getLabel()); description.setText(item.getLabel());
description.setEllipsize(TruncateAt.END); description.setEllipsize(TruncateAt.END);
description.setMaxLines(2); description.setMaxLines(2);
...@@ -638,9 +639,10 @@ public abstract class PaymentRequestSection extends LinearLayout implements View ...@@ -638,9 +639,10 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
} }
TextView amount = new TextView(context); TextView amount = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending() ApiCompatibilityUtils.setTextAppearance(amount,
? R.style.PaymentsUiSectionPendingTextEndAligned item.getIsPending()
: R.style.PaymentsUiSectionDescriptiveTextEndAligned); ? R.style.TextAppearance_PaymentsUiSectionPendingTextEndAligned
: R.style.TextAppearance_PaymentsUiSectionDescriptiveTextEndAligned);
amount.setText(createValueString(item.getCurrency(), item.getPrice(), false)); amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));
// Each item is represented by a row in the GridLayout. // Each item is represented by a row in the GridLayout.
...@@ -931,8 +933,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View ...@@ -931,8 +933,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
if (mRowType == OPTION_ROW_TYPE_OPTION) { if (mRowType == OPTION_ROW_TYPE_OPTION) {
// Show the string representing the EditableOption. // Show the string representing the EditableOption.
ApiCompatibilityUtils.setTextAppearance(labelView, ApiCompatibilityUtils.setTextAppearance(labelView,
isEnabled ? R.style.BlackTitle1 isEnabled ? R.style.BlackTitle1 : R.style.BlackDisabledText1);
: R.style.PaymentsUiSectionDisabledText);
labelView.setText(convertOptionToString(mOption, false, /* excludeMainLabel */ labelView.setText(convertOptionToString(mOption, false, /* excludeMainLabel */
mDelegate.isBoldLabelNeeded(OptionSection.this), mDelegate.isBoldLabelNeeded(OptionSection.this),
false /* singleLine */)); false /* singleLine */));
...@@ -943,7 +944,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View ...@@ -943,7 +944,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
R.dimen.payments_section_add_button_height); R.dimen.payments_section_add_button_height);
ApiCompatibilityUtils.setTextAppearance( ApiCompatibilityUtils.setTextAppearance(
labelView, R.style.EditorDialogSectionAddButtonLabel); labelView, R.style.TextAppearance_EditorDialogSectionAddButton);
labelView.setMinimumHeight(buttonHeight); labelView.setMinimumHeight(buttonHeight);
labelView.setGravity(Gravity.CENTER_VERTICAL); labelView.setGravity(Gravity.CENTER_VERTICAL);
labelView.setTypeface(UiUtils.createRobotoMediumTypeface()); labelView.setTypeface(UiUtils.createRobotoMediumTypeface());
...@@ -952,13 +953,12 @@ public abstract class PaymentRequestSection extends LinearLayout implements View ...@@ -952,13 +953,12 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
columnStart = 0; columnStart = 0;
columnSpan = 4; columnSpan = 4;
ApiCompatibilityUtils.setTextAppearance( ApiCompatibilityUtils.setTextAppearance(labelView, R.style.BlackBody);
labelView, R.style.PaymentsUiSectionDescriptiveText);
} else if (mRowType == OPTION_ROW_TYPE_WARNING) { } else if (mRowType == OPTION_ROW_TYPE_WARNING) {
// Warnings use three columns. // Warnings use three columns.
columnSpan = 3; columnSpan = 3;
ApiCompatibilityUtils.setTextAppearance( ApiCompatibilityUtils.setTextAppearance(
labelView, R.style.PaymentsUiSectionWarningText); labelView, R.style.TextAppearance_PaymentsUiSectionWarningText);
} }
// The label spans two columns if no option or edit icon, or spans three columns if // The label spans two columns if no option or edit icon, or spans three columns if
...@@ -1064,7 +1064,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View ...@@ -1064,7 +1064,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
*/ */
private boolean mSplitSummaryInDisplayModeNormal; private boolean mSplitSummaryInDisplayModeNormal;
/** Indicates whether the summary is set to R.style.PaymentsUiSectionDescriptiveText. */ /** Indicates whether the summary is set to descriptive or title text style. */
private boolean mSummaryInDescriptiveText; private boolean mSummaryInDescriptiveText;
private FocusChangedObserver mFocusChangedObserver; private FocusChangedObserver mFocusChangedObserver;
...@@ -1289,10 +1289,10 @@ public abstract class PaymentRequestSection extends LinearLayout implements View ...@@ -1289,10 +1289,10 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
if (selectedItem == null) { if (selectedItem == null) {
setLogoDrawable(null); setLogoDrawable(null);
// Section summary should be displayed as R.style.PaymentsUiSectionDescriptiveText. // Section summary should be displayed as descriptive text style.
if (!mSummaryInDescriptiveText) { if (!mSummaryInDescriptiveText) {
ApiCompatibilityUtils.setTextAppearance( ApiCompatibilityUtils.setTextAppearance(
getSummaryLeftTextView(), R.style.PaymentsUiSectionDescriptiveText); getSummaryLeftTextView(), R.style.BlackBody);
mSummaryInDescriptiveText = true; mSummaryInDescriptiveText = true;
} }
SectionUiUtils.showSectionSummaryInTextViewInSingeLine( SectionUiUtils.showSectionSummaryInTextViewInSingeLine(
......
...@@ -1055,7 +1055,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -1055,7 +1055,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
TextView view = new TextViewWithClickableSpans(mContext); TextView view = new TextViewWithClickableSpans(mContext);
view.setText(spannableMessage); view.setText(spannableMessage);
view.setMovementMethod(LinkMovementMethod.getInstance()); view.setMovementMethod(LinkMovementMethod.getInstance());
ApiCompatibilityUtils.setTextAppearance(view, R.style.PaymentsUiSectionDescriptiveText); ApiCompatibilityUtils.setTextAppearance(view, R.style.BlackBody);
// Add paddings instead of margin to let getMeasuredHeight return correct value for section // Add paddings instead of margin to let getMeasuredHeight return correct value for section
// resize animation. // resize animation.
......
...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.widget; ...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.widget;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
...@@ -65,8 +64,6 @@ public final class DualControlLayout extends ViewGroup { ...@@ -65,8 +64,6 @@ public final class DualControlLayout extends ViewGroup {
*/ */
public static Button createButtonForLayout( public static Button createButtonForLayout(
Context context, boolean isPrimary, String text, OnClickListener listener) { Context context, boolean isPrimary, String text, OnClickListener listener) {
int textColorLink = ApiCompatibilityUtils.getColor(
context.getResources(), R.color.default_text_color_link);
int buttonColor = int buttonColor =
ApiCompatibilityUtils.getColor(context.getResources(), R.color.light_active_color); ApiCompatibilityUtils.getColor(context.getResources(), R.color.light_active_color);
...@@ -75,14 +72,14 @@ public final class DualControlLayout extends ViewGroup { ...@@ -75,14 +72,14 @@ public final class DualControlLayout extends ViewGroup {
primaryButton.setId(R.id.button_primary); primaryButton.setId(R.id.button_primary);
primaryButton.setOnClickListener(listener); primaryButton.setOnClickListener(listener);
primaryButton.setText(text); primaryButton.setText(text);
primaryButton.setTextColor(Color.WHITE); ApiCompatibilityUtils.setTextAppearance(primaryButton, R.style.WhiteButtonText);
return primaryButton; return primaryButton;
} else { } else {
Button secondaryButton = ButtonCompat.createBorderlessButton(context); Button secondaryButton = ButtonCompat.createBorderlessButton(context);
secondaryButton.setId(R.id.button_secondary); secondaryButton.setId(R.id.button_secondary);
secondaryButton.setOnClickListener(listener); secondaryButton.setOnClickListener(listener);
secondaryButton.setText(text); secondaryButton.setText(text);
secondaryButton.setTextColor(textColorLink); ApiCompatibilityUtils.setTextAppearance(secondaryButton, R.style.BlueButtonText2);
return secondaryButton; return secondaryButton;
} }
} }
......
...@@ -76,7 +76,7 @@ public class HintedDropDownAdapterWithPlusIcon<T> extends HintedDropDownAdapter< ...@@ -76,7 +76,7 @@ public class HintedDropDownAdapterWithPlusIcon<T> extends HintedDropDownAdapter<
// Set the correct appearance, face and style for the text. // Set the correct appearance, face and style for the text.
ApiCompatibilityUtils.setTextAppearance( ApiCompatibilityUtils.setTextAppearance(
mTextView, R.style.EditorDialogSectionAddButtonLabel); mTextView, R.style.TextAppearance_EditorDialogSectionAddButton);
mTextView.setTypeface(UiUtils.createRobotoMediumTypeface()); mTextView.setTypeface(UiUtils.createRobotoMediumTypeface());
// Padding at the bottom of the dropdown. // Padding at the bottom of the dropdown.
......
...@@ -18,33 +18,27 @@ ...@@ -18,33 +18,27 @@
<style name="ButtonCompatBorderlessOverlay"> <style name="ButtonCompatBorderlessOverlay">
<item name="android:buttonStyle">@style/ButtonCompatBorderless</item> <item name="android:buttonStyle">@style/ButtonCompatBorderless</item>
</style> </style>
<!-- TODO(https://crbug.com/856244): Remove textAllCaps and textSize from button style and move
it to button textAppearance styles, and figure out why the feed library styles overrides
styles here. -->
<style name="ButtonCompatBase"> <style name="ButtonCompatBase">
<item name="android:minWidth">88dp</item> <item name="android:minWidth">88dp</item>
<item name="android:minHeight">36dp</item> <item name="android:minHeight">36dp</item>
<item name="android:textSize">14sp</item>
<item name="android:paddingStart">20dp</item> <item name="android:paddingStart">20dp</item>
<item name="android:paddingEnd">20dp</item> <item name="android:paddingEnd">20dp</item>
<item name="android:paddingTop">5dp</item> <item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item> <item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">true</item>
<item name="android:focusable">true</item> <item name="android:focusable">true</item>
<item name="android:clickable">true</item> <item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|center_horizontal</item> <item name="android:gravity">center_vertical|center_horizontal</item>
</style> </style>
<!-- TODO(https://crbug.com/856244): Remove textStyle from button style and move it to button
textAppearance styles. -->
<style name="ButtonCompat" parent="ButtonCompatBase"> <style name="ButtonCompat" parent="ButtonCompatBase">
<item name="android:background">@drawable/button_compat_shape</item> <item name="android:background">@drawable/button_compat_shape</item>
<item name="android:textStyle">bold</item>
</style> </style>
<style name="ButtonCompatBorderless" parent="ButtonCompat"> <style name="ButtonCompatBorderless" parent="ButtonCompat">
<item name="android:background">?android:attr/selectableItemBackground</item> <item name="android:background">?android:attr/selectableItemBackground</item>
</style> </style>
<!-- Used by Chrome and Content --> <!-- Used by Chrome and Content -->
<!-- TODO(huayinz): Update prefixes for text appearance styles in ui/android. -->
<style name="TextAppearance" parent="android:TextAppearance" tools:ignore="UnusedResources" />
<style name="RobotoMediumStyle"> <style name="RobotoMediumStyle">
<item name="android:fontFamily">sans-serif</item> <item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
...@@ -107,6 +101,7 @@ ...@@ -107,6 +101,7 @@
<style name="BlackButtonText" parent="RobotoMediumStyle" tools:ignore="UnusedResources"> <style name="BlackButtonText" parent="RobotoMediumStyle" tools:ignore="UnusedResources">
<item name="android:textColor">@color/black_alpha_54</item> <item name="android:textColor">@color/black_alpha_54</item>
<item name="android:textSize">@dimen/text_size_medium</item> <item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:textAllCaps">true</item>
</style> </style>
<style name="BlackLink" tools:ignore="UnusedResources"> <style name="BlackLink" tools:ignore="UnusedResources">
<item name="android:textColor">@color/black_alpha_54</item> <item name="android:textColor">@color/black_alpha_54</item>
...@@ -156,10 +151,12 @@ ...@@ -156,10 +151,12 @@
<style name="BlueButtonText1" parent="RobotoMediumStyle" tools:ignore="UnusedResources"> <style name="BlueButtonText1" parent="RobotoMediumStyle" tools:ignore="UnusedResources">
<item name="android:textColor">@color/modern_blue_300</item> <item name="android:textColor">@color/modern_blue_300</item>
<item name="android:textSize">@dimen/text_size_medium</item> <item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:textAllCaps">true</item>
</style> </style>
<style name="BlueButtonText2" parent="RobotoMediumStyle" tools:ignore="UnusedResources"> <style name="BlueButtonText2" parent="RobotoMediumStyle" tools:ignore="UnusedResources">
<item name="android:textColor">@color/modern_blue_600</item> <item name="android:textColor">@color/modern_blue_600</item>
<item name="android:textSize">@dimen/text_size_medium</item> <item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:textAllCaps">true</item>
</style> </style>
<style name="BlueLink1" tools:ignore="UnusedResources"> <style name="BlueLink1" tools:ignore="UnusedResources">
<item name="android:textColor">@color/modern_blue_600</item> <item name="android:textColor">@color/modern_blue_600</item>
......
...@@ -4,11 +4,8 @@ ...@@ -4,11 +4,8 @@
found in the LICENSE file. --> found in the LICENSE file. -->
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Buttons --> <!-- Buttons -->
<!-- TODO(https://crbug.com/856244): Remove fontFamily from button style and move
it to button textAppearance styles. -->
<style name="ButtonCompat" parent="ButtonCompatBase"> <style name="ButtonCompat" parent="ButtonCompatBase">
<item name="android:background">@drawable/button_compat</item> <item name="android:background">@drawable/button_compat</item>
<item name="android:fontFamily">sans-serif-medium</item>
</style> </style>
<style name="ButtonCompatBorderless" parent="ButtonCompat"> <style name="ButtonCompatBorderless" parent="ButtonCompat">
<item name="android:background">@drawable/button_borderless_compat</item> <item name="android:background">@drawable/button_borderless_compat</item>
......
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