173 Commits

Author SHA1 Message Date
Material Design Team
feee8126e6 Automated g4 rollback of changelist 165622891.
*** Reason for rollback ***

Breaks GMM

*** Original change description ***

Reposition label to adapt to box surroundings.

Move the collapsed and expanded bounds of the floating label towards where each belongs. This commit is the first stage in setting the floating label's bounds, so it avoids calculating the exact dimensions based on internal dimensions. The label positioning work is being broken up into stages since the internal dimensions of the text field will likely change either in an upcoming design rethink and while adding the dimension parameters. The final d...

***

PiperOrigin-RevId: 165664978
2017-09-21 14:32:18 -04:00
afohrman
84d3d9ef92 Reposition label to adapt to box surroundings.
Move the collapsed and expanded bounds of the floating label towards where each belongs. This commit is the first stage in setting the floating label's bounds, so it avoids calculating the exact dimensions based on internal dimensions. The label positioning work is being broken up into stages since the internal dimensions of the text field will likely change either in an upcoming design rethink and while adding the dimension parameters. The final dimensions will be set once the design is agreed upon, and probably during the dimension parameterization phase.

PiperOrigin-RevId: 165622891
2017-09-21 14:31:54 -04:00
afohrman
a0550d04c5 Add box for text field.
Add a background box for text field to create the text field box. This does not upgrade all "line" text fields, it simply adds another style for text fields that users can opt in to in order to get the box version.

This commit adds a basic grey background box. Not included in this commit:
- Padding/positioning for the label to adjust to being in the box
- Dark/light theme versions
- Exact dimensions and colors

PiperOrigin-RevId: 165596665
2017-09-21 14:31:29 -04:00
miguely
b352fa92f8 BackLayer: Make Sibling Behavior listen to changes inside the BackLayerLayout (views changing size or relayout) to react automatically to changes in content.
Before, if there was any change to the layout inside BackLayerLayout while the back layer was already expanded, the developer had to manually call setExpanded(true) for it to animate to the new size.

Now, the behavior reacts automatically and animates the size change on its own, simplifying the code path and allowing more flexibility.

PiperOrigin-RevId: 165175310
2017-09-21 14:31:01 -04:00
Alan Viverette
d16cead6c8 Remove unnecessary casts on calls to findViewById
Bug: 24137209
Test: make -j32
Change-Id: I04084b2d05ddd7afaa160a76efe0b0d0c8eb5f00
PiperOrigin-RevId: 165042386
2017-09-21 14:30:28 -04:00
Aurimas Liutikas
c367e56554 Clean up an assortment of Error-Prone warnings.
Test: ./gradlew assembleError prone still works (and now with fewer warnings
TM)
Change-Id: I9e0af18b49a3eff1dd7ac8edc5a2873f93bb844e
PiperOrigin-RevId: 165021145
2017-09-21 14:30:11 -04:00
Kirill Grouchnikov
3c1a8594f5 Don't crash in AppBarLayout inflation
Specific attributes used in AppBarLayout's theme will cause
the super constructor to call onCreateDrawableState before
class-level fields are initialized. Move the creation of temp
array to be on-demand.

Bug: 37460722
Test: ./gradlew support-design:connectedCheck --info --daemon
-Pandroid.testInstrumentationRunnerArguments.class=android.support.design.widget.AppBarWithScrollbarsTest
Change-Id: I086f25c676201876fd76cd3684afcab7e09436d0
PiperOrigin-RevId: 165010107
2017-09-21 14:25:11 -04:00
Yuichi Araki
a9f3c2b463 Status bar background for BottomSheetDialog
Bug: 31303656
Test: Manual & existing tests on 15, 18, 19, 21 and 25
Change-Id: I72240894848ae1e9505679f2e4517c152fa3c4bf
PiperOrigin-RevId: 164946739
2017-09-21 14:24:45 -04:00
markwei
e02f108d03 Base theme's colorSecondary defaults to colorPrimary.
This allows an app theme to only define colorPrimary variants, and get have that be applied by default to all controls.
Legacy apps overwrite colorAccent, which controls will still honor.

PiperOrigin-RevId: 164890003
2017-09-21 14:24:25 -04:00
gauthams
6c84bf2a45 Add style for M2 text button, and add text button demo to Material Components catalog app.
PiperOrigin-RevId: 164667764
2017-09-21 14:23:21 -04:00
miguely
4ef1f94011 Backlayer: Keep the value of expanded across activity restarts and config changes using onSaveInstanceState and onRestoreInstanceState.
This CL also changes the API from a explicit expand()/collapse() method duo to a single setExpanded(boolean) to match other expandable widgets in MDC, for consistency.

This is a breaking change but there has been no release of MDC that contains BackLayerLayout in a usable state, so this is the right time to do this kind of change.

PiperOrigin-RevId: 164664813
2017-09-21 14:22:28 -04:00
miguely
1a17221ee3 Fix accessibility focus on the back layer and the content layer.
Problem 1. The back layer contains all views for an expanded experience, even
if they are hidden behind the content layer, this makes them accessible through
Talkback when the back layer is collapsed when all views outside of
CollapsedBackLayerContents must be for all intents and purposes disabled. They
still need to remain visible to accomodate for semi transparent views, so
changing their visibility to GONE is not an option.

Solution: Add ChildViewAccessibilityHelper that keeps track of the
importantForAccessibility property for subviews of the BackLayer and overrides
them to IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDENTS when collapsed and then
reverts them to their original values when the back layer is expanded.

- Caveat: This new object has to implement ViewGroup.OnHierarchyChangeListener
so it can remove mappings for removed views, this way guaranteeing there is no
memory leak. This also means users of BackLayerLayout MUST NOT set their own
OnHierarchyChangeListener.

- Caveat 2: this new object does not modify any CollapsedBackLayerContents,
since views in that subview must still be accessible when collapsed.

Problem 2. When the backlayer expands, the content layer remains active through
accessibility services, we want to completely disable it. Furthermore a content
description needs to be set on the content layer view that may not match what
it already has.

Solution: Add ContentViewAccessibilityPropertiesHelper that overrides the
content layer's contentDescription, importantForAccessibility and focusable
properties (and reverts them once the back layer is collapsed), and reuses the
ChildViewAccessibilityHelper to make its child views not focusable.

Tested: Sadly this is too hard to test on Espresso, I tested this manually, I'm
trying to find a way to test them automatically.
PiperOrigin-RevId: 164661912
2017-09-21 14:21:44 -04:00
markwei
9a32f67d40 Pull AnimationUtils into a new package.
PiperOrigin-RevId: 163743184
2017-09-21 14:21:16 -04:00
markwei
659b5d16bc Roll forward separating ExpandableWidget/TransformationWidget and ExpandableBehavior/ExpandableTransformationBehavior.
Removes onSaveInstanceState() and onRestoreInstanceState() from the ExpandableWidget interface. Those methods required all descendent subclass Views to declare those methods to be public, which is not ideal given how many FAB subclasses there are.

Those interface methods were mostly used for their javadoc, which is now moved into the interface javadoc.

PiperOrigin-RevId: 163440160
2017-09-21 14:20:30 -04:00
miguely
5694bee92b Explain the requirement of layout_gravity, gravity and orientation in
BackLayerLayout.

This change also adds details on why all of these could not be consolidated
into less attributes and generally improves the usage guide.

PiperOrigin-RevId: 163094493
2017-09-21 14:20:08 -04:00
markwei
f61171a94b Roll back ExpandableTransformation separation.
This broke clients that subclassed ExpandableFloatingActionButton and overrode onSaveInstanceState(). Because those subclasses declared the methods as protected, it conflicts with this commit which makes them public.

Will roll-forward with client fixes.

PiperOrigin-RevId: 162844548
2017-09-21 14:19:37 -04:00
markwei
64f930f2a7 Separate ExpandableWidget and ExpandableTransformationWidget.
Separate ExpandableBehavior and ExpandableTransformationBehavior.

ExpandableWidget - for widgets that have expanded state, like BackLayerLayout:
{g,s}etExpanded()
on{Save,Restore}InstanceState()

ExpandableBehavior - for behaviors that want to react to expanded state change, like BackLayerSiblingBehavior:
onLayoutChild() // Layouts the content, and animates the content to a new expanded position when BLL's expanded children change size.
onExpandedStateChange() // Animates the content position when expanded state changes.

ExpandableTransformationWidget - for widgets that transform during expansion, like FAB:
{g,s}etExpandedComponentIdHint()
Will also include these in the future:
getBackgroundDrawable() // Shape drawable includes color, bounds, shape, elevation
getForegroundDrawable()
etc

ExpandableTransformationBehavior - for behaviors that want to react to expanded state change by transforming, like FabTransformationSheetBehavior:
onCreateExpandedStateChangeAnimation() // Animates the FAB and sheet when expanded state changes.

PiperOrigin-RevId: 162809090
2017-09-21 14:18:58 -04:00
afohrman
75204528b9 Reformat layout files in lib directory.
Most of the layout files were not following our code style and followed an attribute ordering scheme that didn't make very much sense (ex: putting an attribute's format before its name).

Reformatting these files in a separate commit will help prevent formatting changes distracting from the main point of commits.

PiperOrigin-RevId: 162670506
2017-09-21 13:00:16 -04:00
Material Design Team
fd840cbf9a The foundation part of the Dynamic Persistent Sheet concept implementation
This change adds all the foundation code needed:
+ demo in the Catalog,
+ persistentsheet package with 2 classes:
  * PersistentSheet,
  * PersistentSheetTransformationBehavior

Instead of a proper expansion animation, a placeholder animation copied from FAB transformations is added. Proper animations to be added later.

PiperOrigin-RevId: 162641104
2017-09-21 12:13:02 -04:00
afohrman
0c49c64a57 Turn hint/label to error color when error is set.
Adds functionality to turn the floating label, or "hint", to the error color when the error is set. The error color for the label will match whatever the error color is set to via app:errorTextAppearance. In the case where no custom errorTextAppearance is set, the label gets set to the error color's default color, which is red/dark pink, depending on whether the text field is used in a dark or light theme.

PiperOrigin-RevId: 162553182
2017-09-21 12:12:31 -04:00
markwei
dbab5c7ef0 Add test for FabTransformation*Behaviors.
PiperOrigin-RevId: 162525305
2017-09-21 12:11:50 -04:00
markwei
9cabd53c7f Fix for missing BaseSavedState(Parcel, ClassLoader) on APIs < 24.
Inherit from support-lib AbsSavedState instead of the framework BaseSavedState.

PiperOrigin-RevId: 162500649
2017-09-21 12:10:22 -04:00
afohrman
66ff202b44 Fix reference equality comparison warnings for typeface.
The typeface comparisons in CollapsingTextHelper were triggering a ReferenceEquality warning. Changing to an Objects.equals comparison did not fix the problem, because Objects is not available down to API level 15. I added a SuppressWarnings annotation to match the way this already is addressed in TextInputLayout.

PiperOrigin-RevId: 162399064
2017-09-21 12:10:07 -04:00
afohrman
b28f0e0996 Add helper text feature to TextInputLayout.
This commit adds functionality to TextInputLayout to support helper text, as outlined in spec: https://material.io/guidelines/components/text-fields.html#text-fields-layout.

This is an initial implementation of helper text. It is a large commit, and in order to avoid making it any larger, it does not include the following things:

- Setting helper text via XML attribute

PiperOrigin-RevId: 162390341
2017-09-21 12:09:20 -04:00
miguely
2d618793dd Adds support for more than one expanded state for the BackLayerLayout.
The content for the backlayer should be able to change in runtime to allow for multiple experiences in the backlayer. Furthermore, changing to a different experience should not imply collapsing and re-expanding the backlayer, it should happen in-place with the content layer sliding to accommodate the size of the new content.

If expand is called when the backlayer is already expanded then the backlayer
animates a possible size change.

If there is no need to change the size then the duration for the animation is
zero.

On the side, this changes BackLayer to be a LinearLayout.

PiperOrigin-RevId: 162277051
2017-09-21 12:00:21 -04:00
travisc
3ec57f2dab Roll forward ExpandableTransformationBehavior changes since the CL it depends on was rolled forward.
PiperOrigin-RevId: 162002644
2017-09-21 11:59:09 -04:00
travisc
329cc2d267 Roll forward. Fixes the crash on Parcelable restoration.
PiperOrigin-RevId: 161999957
2017-09-21 11:58:17 -04:00
travisc
680e3c3a25 Roll back FAB expand/collapse state due to crash it introduces.
PiperOrigin-RevId: 161864354
2017-09-21 11:57:01 -04:00
travisc
9381e4848b Roll back later FAB expansion work because it depends on a change that needs to be rolled back.
PiperOrigin-RevId: 161860435
2017-09-21 11:56:33 -04:00
markwei
02f1e5cb83 ExpandableTransformationBehavior is an abstract base class for all behaviors that react to changes in an ExpandableWidget's expanded state.
FabTransformationSheetBehavior and FabTransformationScrimBehavior implement
specific variations of an ExpandableTransformationBehavior.

These Behavior currently just does a simple fade of the FAB, sheet, and scrim.

PiperOrigin-RevId: 161758301
2017-09-21 11:55:43 -04:00
markwei
8571cd7386 Add expand/collapse state to FloatingActionButton.
After this CL, FAB is able to keep an `expanded` state. When the state changes,
it dispatches an event to dependent Behaviors.

This change does not include any XML attributes.

PiperOrigin-RevId: 161757314
2017-09-21 11:32:17 -04:00
miguely
9acb393c41 Move BackLayerLayout to use LinearLayout instead of RelativeLayout.
In previous code reviews there was a concern over the performance hit of
RelativeLayout's double measurement, and BackLayerLayout's own double measurement.

As a compromise we chose to use LinearLayout instead. Furthermore after
switching to LinearLayout, the EndBackLayerLayoutTest works, so this commit
also commits that new test.

PiperOrigin-RevId: 161720799
2017-09-21 11:31:30 -04:00
miguely
025f75b4cf Generalizes all test logic to abstract the position of the BackLayer.
Adds concrete tests for Start, Top and Bottom backlayers.

Note: EndBackLayerLayoutTest has not been added in this CL because it is
failing over layout issues. These issues are not related directly to the core
functionality of the BackLayerLayout, but it still has to be fixed. Punting
this to a separate CL.
PiperOrigin-RevId: 161667143
2017-09-21 11:29:43 -04:00
markwei
d9306c69c1 Create new MaterialComponent themes with new color scheme attributes.
PiperOrigin-RevId: 160319995
2017-09-21 11:26:31 -04:00
miguely
fb9092098a Add the ability to hide and expose the Back Layer.
-The exposure and hide actions are animated, and have before/after callbacks.
-Clicks on the content layer when the backlayer is exposed are hijacked to close the back layer.
-The animations do not relayout, by simply sliding the boundaries (bottom/left/right/top).

PiperOrigin-RevId: 160315361
2017-09-21 11:25:14 -04:00
afohrman
127dfe1255 Add graceful degradation for character counter and label text overflow color.
Previously, the character counter and label overflow color ended up as Color.MAGENTA, which actually is a sickly pink color. This appears to have been happening when the theme doesn't extend from Theme.Design, and therefore doesn't have textErrorColor. On API 23 and above, it gets set to MAGENTA instead of throwing an exception. The only reason this pink color was being used for the character counter and not the error text is because there already a fix for the error text - it just wasn't applied to the character counter.

I pulled the logic for the fix out to make this graceful degradation code reusable for both error and character text, and for future situations like this.

PiperOrigin-RevId: 159229718
2017-09-21 11:23:47 -04:00
afohrman
73cb135c15 Update vertical motion for TextInputLayout's error text.
Motion additions/updates in this change:
- Added animation for error text's translation down
- Updated durations and interpolators for the opacity in and out animations

These changes roll forward changes that were previously rolled back because they broke screenshot tests.

PiperOrigin-RevId: 158881906
2017-06-14 16:38:11 -07:00
travisc
06b88e84ad Remove the split base/ics/lollipop directories.
The implementation in ics/ was the only remaining implementation of that class,
so it made sense to move it directly into src/. Most of the implementations in
base/ were the only remaining implementations, and thus also made sense to move
into src/.

The remaining classes were already post-fixed with Lollipop, so I see very
little value in maintaining separate source directories for them (and I know
these separate directories have also been flagged as confusing). They've all
been moved into src/ as well now. I also renamed FloatingActionButtonLollipop
to FloatingActionButtonImplLollipop here, as that better describes what it is
a version of.

PiperOrigin-RevId: 158187999
2017-06-14 16:37:39 -07:00
afohrman
94947cde8a Broke some screenshot tests.
PiperOrigin-RevId: 157239931
2017-06-14 16:33:59 -07:00
afohrman
63acb542ed Update motion for TextInputLayout's error state.
Motion additions/updates in this change:
- Added animation for error text's translation down
- Updated durations and interpolators for the opacity in and out animations

PiperOrigin-RevId: 157220100
2017-06-14 16:32:30 -07:00
gauthams
60549808c5 Fix divide-by-zero crash when building BottomNavigationMenu with <2 children and shifting mode enabled.
PiperOrigin-RevId: 156888556
2017-05-24 16:37:07 -07:00
gauthams
c8052c3e2f Modify setShiftingMode() in BottomNavigationItemView to call setChecked() if the item view has already been initialized, so that shifting mode changes are immediately visible without having to re-initialize the view.
Also setting shifting mode before initializing view in BottomNavigationMenuView's updateMenu(), for consistency with buildMenu().

PiperOrigin-RevId: 156800545
2017-05-24 16:36:29 -07:00
afohrman
78eb50a405 Update motion for TextInputLayout's active state.
Motion updates in this change:
- Shortened the duration for the label scale
- Changed the interpolators from linear to FastOutSlowIn

PiperOrigin-RevId: 156553820
2017-05-24 16:35:55 -07:00
miguely
644139fb99 Add a BackLayerLayout and BackLayerSiblingBehavior + tests.
These are the foundation for the back layer functionality. The behavior
does the heavy lifting to measure the adjacent content view.

As of now this only lays out the views correctly in the hidden state, it doesn't support exposing the back layer at all, yet. Full of TODOs, this is just a skeleton.

PiperOrigin-RevId: 156334640
2017-05-24 16:33:21 -07:00
gauthams
08c783554a Update documentation for methods to set and get shifting mode on BottomNavigationView
PiperOrigin-RevId: 156251192
2017-05-24 16:31:55 -07:00
gauthams
eb96b9a358 Fix crash in BottomNavigationMenuView when updateMenuView is called while mMenu or mButtons is null
PiperOrigin-RevId: 156243521
2017-05-16 16:03:49 -07:00
gauthams
8493677be9 Add option to disable shifting mode even on BottomNavigationViews with 3+ children
Fixes #22.

PiperOrigin-RevId: 156126715
2017-05-16 16:02:31 -07:00
gauthams
32b1f744e4 Update BottomNavigationView onMeasure to properly measure with invisible children
PiperOrigin-RevId: 155899080
2017-05-12 13:18:19 -07:00
gauthams
71c3e81905 Don't skip adding non-visible children in BottomNavigationView to avoid NPE when accessing those
PiperOrigin-RevId: 155893998
2017-05-12 13:18:02 -07:00
gauthams
d15d791fb7 Fix NPE on bottom nav menu update, and add test for this case.
PiperOrigin-RevId: 155776319
2017-05-11 13:00:34 -07:00