242 Commits

Author SHA1 Message Date
afohrman
8a72126daa Use color int instead of ColorStateList for box stroke color.
This is the first step in adding states to the outline text box. The states implementation plan is to handle the box's states similar to how TextInputLayout already handles states, and moving the box stroke color to be a color int sets the stage for that change.

In a nutshell, the states implementation plan is to add an updateBoxState() method in TextInputLayout's overridden drawableStateChanged(), and change the parameters affected by state in that method. Since updateBoxState() will handle changing the colors, and since GradientDrawable doesn't have support for ColorStateLists pre-21, it makes more sense for mBoxStrokeColor to be a color int. That way, TextInputLayout can handle all of the states the same way, instead of flagging different versions and essentially building states twice.

This commit changes the mBoxStrokeColor reference to point to a color int resource, and updates the getters, setters, documentation, the catalog demo entry, and the relevant tests to reflect the new variable type.

PiperOrigin-RevId: 171831287
2017-11-14 13:38:36 -05:00
Kirill Grouchnikov
559d400937 Fix dodge constants for CoordinatorLayout
Use consistent values for right dodging + add test coverage

Bug: 65976973
Test: ./gradlew design:connectedCheck --info --daemon
-Pandroid.testInstrumentationRunnerArguments.class=android.support.design.widget.AppBarWithDodgingTest
Change-Id: I48b5f4ec9b8e5d5484fcd846fd2f305d1987a5ef
PiperOrigin-RevId: 171615802
2017-11-14 13:38:08 -05:00
markwei
98bc2625c9 Support compat vector drawables in FAB demos.
Fix bug in FAB Transformation where drawable.setAlpha() was called without mutate().
This affected other demos that used the same resource.

PiperOrigin-RevId: 171614982
2017-11-14 13:37:13 -05:00
markwei
1f3fb664cc MotionSpec API change.
Now it contains two static factory methods: loadFromAttribute() and loadFromResource().

PiperOrigin-RevId: 171216945
2017-11-13 14:23:49 -05:00
markwei
219d4e5137 When recomputing image matrix, use current scale value instead of 1f.
Move updateImageMatrixScale() call from setImageResource() to setImageDrawable() to catch all image drawable changes.
Minor name changes for consistency.

This change should result in identical behavior if previous scale was 1f.

PiperOrigin-RevId: 171204342
2017-11-13 14:23:13 -05:00
Material Design Team
62c0868439 Recompute FAB image matrix when the button's image drawable changes.
#lb-fab

PiperOrigin-RevId: 171175040
2017-11-13 14:22:42 -05:00
markwei
108ba28d56 Fix bug where the same temp Matrix instance was being referenced beyond its valid timeframe.
There were two major bugs:

1. The temp instance toValue passed to ObjectAnimator.ofObject(view, prop, eval, toValue) does not get read right away.
Instead, ObjectAnimator stores it as a reference. This is problematic because the temp instance is used to make other calculations, and its value overwritten before ObjectAnimator reads it.

2. ImageMatrixProperty#get was returning the instance from ImageView#getImageMatrix(), which is not a copy, but the ImageView's instance itself.
This is problematic because ObjectAnimator stores it as the fromValue and reads from it on each frame. However, the ObjectAnimator is also setting new values on the same instance each frame due to animation.

The fix is to make a copy of the temp instance when it is not read right away. This way, ObjectAnimator stores a copy which is not subject to being overwritten.

PiperOrigin-RevId: 171169919
2017-11-13 14:21:40 -05:00
markwei
1e224bc7f3 New motion specs for FAB show/hide animation.
PiperOrigin-RevId: 171078110
2017-11-13 14:21:12 -05:00
markwei
5edfba0242 BackLayerLayout cleanup.
BackLayerLayout:
- Expanded state is saved and restored via ExpandableWidgetHelper across configuration changes.
- BackLayerLayout and BackLayerSiblingBehavior no longer keep references to each other, minimizing stale state.
- All state changes now go through CoordinatorLayout.dispatchDependentViewsChanged(), mirroring other MDC-Android components like FAB Transformation and dynamic persistent sheet.

BackLayerSiblingBehavior:
- The behavior is now an ExpandableBehavior, mirroring other MDC-Android components like FAB Transformation and dynamic persistent sheet.
- Animates state changes using both position and translation, better separating its semantic meanings:
 - BLL's collapsed size determines the sibling's position, which never changes.
 - BLL's expanded size determines its translation, which is animated.
PiperOrigin-RevId: 171064071
2017-11-13 14:19:07 -05:00
afohrman
e97e947173 Create label cutout for outline box.
Use PorterDuff modes to create a cutout for the label when using the outline box version of TextInputLayout.

This commit focuses on creating the cutout functionality. The padding and bounds aren't the focus of this commit, and they aren't quite right yet. Measurements will be addressed in a future commit.

PiperOrigin-RevId: 170855509
2017-11-13 14:18:15 -05:00
afohrman
6591f2ba73 Streamline top margin label calculations.
Consolidate calculations for the top margin offset into label calculation methods. This work will make it easier to set the cutout bounds, and to do other dimension work (height parameter, padding work, etc.).

PiperOrigin-RevId: 170779660
2017-11-13 14:17:37 -05:00
afohrman
78ec4eb97d Fix screenshot test failures.
The screenshot tests showed a diff because of a change in the way the collapsed height was being measured. It used to be measured as -ascent, but it was changed to measure the text using the more traditional descent - ascent. This commit changes the collapsed text measurement back to -ascent, and should result in no diff.

PiperOrigin-RevId: 170737363
2017-11-10 15:55:42 -05:00
markwei
57b25026ca Automated g4 rollback of changelist 170569328
PiperOrigin-RevId: 170730468
2017-11-10 15:55:14 -05:00
Material Design Team
7f6fe75b9f Automated g4 rollback of changelist 170569077
PiperOrigin-RevId: 170569328
2017-11-10 15:54:24 -05:00
markwei
d48039b988 Parameterize FAB showMotionSpec and hideMotionSpec.
- FAB show/hide animations are now using MotionSpec API.
- New motion specs for FAB show/hide has been created and should behave
identical to before.
- FAB now supports a new iconScale animation that animates the image matrix of
the icon to scale it. The new motion specs are crafted so that iconScale
animations do not play, but jump immediately to the desired scale (1f or 0f) for show/hide.

PiperOrigin-RevId: 170569077
2017-11-10 15:52:59 -05:00
markwei
cde5e2daaa Set FAB scale type to MATRIX.
This is necessary for new FAB animations that animate the icon size.

The image matrix is now manually maintained such that the FAB should look
identical to the previous scale type FIT_CENTER.

PiperOrigin-RevId: 170568882
2017-11-10 15:52:35 -05:00
markwei
8c6f876229 Create AnimatorSetCompat utility class.
I've run into the same AnimatorSet bug 3 times, so it's worth fixing this in one place.
I've changed all instances of AnimatorSet#playTogether to use this compat class.

PiperOrigin-RevId: 170568456
2017-11-10 15:52:07 -05:00
markwei
d4b3d4623b Use new MotionSpec API for FAB Transformations.
We can now declare our animation constants as an XML resource.

PiperOrigin-RevId: 170568151
2017-11-10 15:51:37 -05:00
markwei
c89dfef597 New MotionSpec API.
Support inflating a MotionSpec from a R.animator resource.
Create a few backwards compatible R.interpolator resources that clients can use for this API.

PiperOrigin-RevId: 170567793
2017-11-10 15:50:23 -05:00
afohrman
585a074ae5 Automated g4 rollback of changelist 170486018
PiperOrigin-RevId: 170512542
2017-11-10 15:50:01 -05:00
afohrman
b93ba27820 Add methods for measuring collapsed text bounds.
Incorporate more robust measurement methods into CollapsingTextHelper, and use those to measure the extra top margin in TextInputLayout.

Before, there was no method to find the exact height of the text in TextInputLayout. All CollapsingTextHelper offered was a getter for the collapsed/expanded text sizes. However, this was not an accurate measurement, since the typeface could change the text dimensions. The expanded and collapsed bounds are also not reliable, because they could be set to a bigger area than the text actually takes up.

This commit adds methods to check the actual measurements of the text, rather than approximations.

PiperOrigin-RevId: 170486018
2017-11-10 15:49:35 -05:00
markwei
6eaa7ebd9d Remove unused parameters from FabTransformationBehavior.onCreateMotionSpec().
The motion spec should be independent of the source and destination widgets.
Add context parameter so we can inflate the motion spec from resources.

PiperOrigin-RevId: 170306303
2017-11-10 15:48:24 -05:00
afohrman
8003f22530 Add color parameter for outline box.
Adds an attribute for the box's stroke (outline) color. Includes a public and private attribute, setters, getters, documentation, and tests.

PiperOrigin-RevId: 170239224
2017-11-10 15:47:23 -05:00
markwei
287187dca0 Create getters and setters for attributes hoveredFocusedTranslationZ and pressedTranslationZ.
This allows clients to animate between a raised and lowered FAB, without having
to introduce a new state dimension.

PiperOrigin-RevId: 170137350
2017-11-10 15:46:50 -05:00
markwei
b3b2e42b1b Add rippleAlpha attribute to FAB.
Ripple color (int) and ripple alpha (state list) are now composited together to create the ripple drawable.

PiperOrigin-RevId: 170129665
2017-11-10 15:44:40 -05:00
markwei
1f90669495 Actually change FAB elevation on API 21.
Listen for onDrawableStateChanged() and manually set the correct elevation without animation.

PiperOrigin-RevId: 170127224
2017-11-10 15:43:53 -05:00
markwei
95a7fcb321 Make FloatingActionButton implement TintableImageSourceView so we can tint its icon pre-21.
Use ColorFilter to support pre-21 tinting.

PiperOrigin-RevId: 170125236
2017-11-10 15:43:26 -05:00
afohrman
cb0b6c4230 Add padding parameter and improve box creation.
This commit improves the box creation process and adds initial padding parameters for the box. For now, these values are only set on the EditText, but to truly update the padding throughout the box, the padding should be adjusted in other places (for example, the label's collapsed and expanded bounds should be updated based on the padding values). Also, some of the official values (top and bottom) don't look quite right at this stage, so they are set to values that look better for now. When padding is addressed fully, these will be set to the correct values.

This commit also adds padding back in where it would get wiped out in API 21 and 22 in ensureBackgroundDrawableStateWorkaround().

The box creation improvements prevent some unnecessary calls to box-specific methods, and a new mEditTextBoundsUpdated flag ensures that the EditText bounds are not repeatedly updated.

PiperOrigin-RevId: 170111678
2017-11-10 15:42:13 -05:00
gauthams
7d45ba1736 Programmatically creating drawable backgrounds for button, and added attributes to control button background color, stroke width and color, corner radius, and inset.
PiperOrigin-RevId: 170103904
2017-11-10 15:41:40 -05:00
markwei
25601df274 Automated g4 rollback of changelist 169728741
PiperOrigin-RevId: 169968826
2017-11-10 15:40:00 -05:00
Miguel Yáñez Barreto
201b67bb20 Set up maven artifact generation for MDC libraries.
- `./gradlew uploadArchives` generates a maven repository with all the libraries that MDC requires and generates.
- Adds a new argument to pass to gradle, -PmavenRepoUrl to customize the maven repository location (it defaults to /tmp/myRepo otherwise). For example `./gradlew uploadArchives -PmavenRepoUrl=file://localhost/Users/miguelandres/myRepo`).
- Added a rootProject.ext.mdcLibraryVersion variable to set all libraries to a matching version when building the maven repository.
- Added a getArchivesBaseName(projectName) function to main build.gradle to generate all of the maven artifactIds programatically.
- Removes Source Jar and javadoc generation, since they have to be adapted to use droiddoc and to contain the entire source across gradle project boundaries (see b111021813 for an example of cross-project boundary javadoc generation)

Closes #45

PiperOrigin-RevId: 169956436
2017-09-25 16:56:58 -04:00
markwei
1b45920a1b Animate FAB elevation for new hovered and focused states.
PiperOrigin-RevId: 169799345
2017-09-25 14:55:02 -04:00
markwei
cc7615998b Remove colorMaterialControl and colorMaterialControlHighlight.
We have no need for these, and they are not currently used anywhere.

PiperOrigin-RevId: 169796990
2017-09-25 14:54:45 -04:00
markwei
3331179bba New intermediary elevation attribute for hovered and focused FAB states.
Legacy FAB has no intermediary elevation states, so hovered_focused matches pressed.

Attributes are not yet read by FAB, will come in later CL.

PiperOrigin-RevId: 169755456
2017-09-25 14:54:14 -04:00
markwei
148141b3af Create separate files for legacy "design" themes/styles and new "mtrl" themes/styles.
PiperOrigin-RevId: 169728741
2017-09-25 14:53:48 -04:00
Juan Pereira
bf5ef89143 [TextInputLayout] Change getTypeFace annotation to @Nullable
Closes #25
Closes #26

PiperOrigin-RevId: 169725951
2017-09-22 16:02:43 -04:00
Kirill Grouchnikov
2ef4aeb4fd Conditional use of workaround for 22-24 devices
Bug: 32136707
Test: ./gradlew support-design:connectedCheck --info --daemon
-Pandroid.testInstrumentationRunnerArguments.class=android.support.design.widget.FloatingActionButtonTest
Change-Id: Icdf198e9923af4baa1456496efdfc25b20abe582
PiperOrigin-RevId: 169627986
2017-09-22 12:15:38 -04:00
markwei
d78b8b4f72 Parameterize scrim color into theme attribute.
Modify FAB Transformation to use theme attribute rather than hardcoded value.
Fix scrim's alpha value to actually reflect 32% black.

PiperOrigin-RevId: 169620100
2017-09-22 12:15:07 -04:00
markwei
50b4dc51cf Restructure library.
PiperOrigin-RevId: 169602341
2017-09-21 18:53:27 -04:00
miguely
289ccd7577 Add explicit exclusions to "**/build/**" in gradle files.
Since our source roots are the project's root directory, generated output falls inside it, unless properly excluded, all intermediate output such as R classes gets recompiled with each gradle pass.

This causes failures because of duplicate R classes.

PiperOrigin-RevId: 169588457
2017-09-21 16:13:59 -04:00
gauthams
ceefd01665 Update M2 baselines to make use of color theming and match latest M2 spec. This work is complete for post-Android-L M2 buttons but ongoing for pre-L buttons and will likely require building the background drawable programmatically.
PiperOrigin-RevId: 169467041
2017-09-21 15:10:22 -04:00
miguely
713ac062ad Update Gradle build to fit our new code structure.
We have subprojects of :lib: because our internal builds are bazel-based. Gradle does not support more than one project at any level with the same name, which is a staple of bazel-based builds, so gradle projects have to be renamed in runtime to include their whole path (see settings.gradle).

Furthermore since every node includes the path up until that node in its name, writing dependencies can get tedious, for this purpose there is a new method in build.gradle called getTransformedProjectPath which takes /-separated project path and turns it into the correct project path, after the rename.

This also updates versions for TargetSdk and SupportLibrary to 26, which is required by the newer code.

PiperOrigin-RevId: 169457686
2017-09-21 15:09:52 -04:00
miguely
0257fed768 Fix Target Api errors:
-DrawableAlphaProperty has a method that can be restructured in a way that the static analysis run by android lint knows that it checks for the right api before using a newer method.
-A method in FabTransformationBehavior had to be annotated with the right TargetApi.
-CollapsedBackLayerLayout needed a @TargetApi on a newer constructor.
-BackLayerLayout needed to switch one method to ViewCompat.

PiperOrigin-RevId: 169446404
2017-09-21 15:09:14 -04:00
miguely
3ed2e987f1 Adding final qualifiers to fix compiler error about these variables being used in inner classes.
PiperOrigin-RevId: 169430210
2017-09-21 15:05:34 -04:00
travisc
fe8541367b Pull CoordintorLayout resources out into their own file.
PiperOrigin-RevId: 169310920
2017-09-21 15:05:00 -04:00
afohrman
9f1a7054fa Make box mode attribute public.
Publicizing the box mode attribute. Box mode was previously kept internal, since it wasn't yet determined whether the box would act as mode-agnostic, and this attribute would go away, or whether there would be a concept of modes, and different behaviors to follow. This has now been decided: the box will use modes to determine functionality (although it won't rely exclusively on the mode - it will still check for null backgrounds, for example). This is the first step in supporting changing the box mode programmatically and at runtime.

PiperOrigin-RevId: 169305486
2017-09-21 15:03:06 -04:00
afohrman
bc24397239 Improve backwards compatibility for box background color.
Use pre-L compatible methods for setting the background color to avoid a crash, and set the background color to default to Color.TRANSPARENT. Previously, in cases where there was no background color, the color defaulted to black in versions before 17. Now when there is no color set, the color is set to Color.TRANSPARENT instead of no color.

The Color.TRANSPARENT default color could have been restricted to pre-17, but I thought it made sense to set a transparent color for all versions, to provide a more consistent way of checking that there is no background color. I'm open to other perspectives on this.

PiperOrigin-RevId: 169300417
2017-09-21 14:57:44 -04:00
miguely
1a07a47211 Cleanup comments
PiperOrigin-RevId: 169278769
2017-09-21 14:55:34 -04:00
markwei
148ccc4274 Make FABs clickable and focusable by default.
PiperOrigin-RevId: 169163245
2017-09-21 14:55:07 -04:00
Material Design Team
47bb0cd722 Make statusBarBackground accept a color reference, to match the support library.
PiperOrigin-RevId: 168869815
2017-09-21 14:54:45 -04:00