16 Commits

Author SHA1 Message Date
Ga\u00ebtan Muller
b3fe6a7f61 [Cleanup] Remove redundant version checks for api <= 19.
Resolves https://github.com/material-components/material-components-android/pull/3849

GIT_ORIGIN_REV_ID=47bb2fcc8031740e5a7d4f741f1ada2af025e126
PiperOrigin-RevId: 632154861
2024-05-09 18:46:02 +00:00
conradchen
25b3c2b15c [TextField] Fix cutout not working when backgroundTint is set
When backgroundTint is set against the AutoCompleteTextView, since the background drawable of it is a LayerDrawable, which will try to get the constant states of its child drawables and create new drawables from them.

In CutoutDrawable we didn't implement that logic - so the constant state returned will be MaterialShapeDrawableState, and therefore the new drawables created are plain MaterialShapeDrawables, instead of CutoutDrawable.

Fixes this by correctly implement drawable state for CutoutDrawable.

Resolves https://github.com/material-components/material-components-android/issues/3041

PiperOrigin-RevId: 508664043
2023-02-10 16:20:37 +00:00
conradchen
a3521784e8 [TextField] Fix label cutout doesn't work on API < 18
Android framework Canvas.clipRect() has a bug with Region.Op.DIFFERENCE when handling bounds.left on APIs lower than 18, which causes text field outlines are still drawn over the label on lower APIs, despite the label area is supposed to be cut out.

Fixes this by bringing back the old solution we were using - "painting out" the label area after the stroke is drawn. Since the implementation is quite complicated, this CL also splits the CutoutDrawable to two inner impl classes to have a better code structure.

Resolves https://github.com/material-components/material-components-android/issues/2811#issuecomment-1196016169

PiperOrigin-RevId: 482013070
2022-10-19 09:20:41 -07:00
pubiqq
b18f45ee99 [TextInputLayout] Delete unused paint
Resolves https://github.com/material-components/material-components-android/pull/2812

    GIT_ORIGIN_REV_ID=b1c718c45ab55d0c70539afe6233d10e883c413a
    Co-authored-by: paulfthomas

PiperOrigin-RevId: 460962180
2022-07-14 18:17:02 +00:00
conradchen
79b2c3d7c5 [TextField] Refine the hint cutout logic
Use canvas.clipRect() to avoid drawing strokes in cutout areas instead of painting-it-white approach we are using right now.

PiperOrigin-RevId: 413246249
2021-12-01 19:06:55 -05:00
conradchen
cf5df22cce [TextField] Fix crashes when text field size is too large
When we try to draw cutout on text field borders, we draw the stroke on a bitmap first. However if the text field is too large, the bitmap size will be too large and cannot be drawn back to the real canvas, which causes crashes.

Adds a workaround/fallback solution to avoid the crash.

PiperOrigin-RevId: 410523013
2021-11-29 16:29:59 +00:00
conradchen
79ae9b1351 [TextInputLayout] Create label cutout only on borders
When a collapsed label is showing, we cutout part of the border of an outlined text input box according to the exact stroke width. However when using rounded corners, there can be slight offsets from where the border is really drawn. Also, if the corner size is large, the part of border we need to cutout might not just be a straight line but contains part of the corner.

However, with the existing cutout logic, we cannot just cutout the whole label area, which will cause the area inside the border also gets cutout, if it has color. This CL changes the cutout drawing logic to only apply the cutout on stroke drawing to fix the issue.

This CL also fixes the bug that when the label is too long, we didn't take the ellipsized text length into account. Creates a variable to store the calculated collapsed text width to fix the issue.

Resolves https://github.com/material-components/material-components-android/issues/2145

PiperOrigin-RevId: 402316057
2021-10-12 11:26:21 -04:00
marianomartin
555356b03f Internal cleanup
PiperOrigin-RevId: 318134343
2020-06-26 14:06:52 -04:00
marianomartin
215a839598 Internal cleanup
PiperOrigin-RevId: 267504117
2019-09-12 13:48:16 -04:00
cketcham
440b6e7753 Add @NonNull and @Nullable annotations
PiperOrigin-RevId: 265057396
2019-08-29 10:30:58 -04:00
afohrman
0aa470af86 Support custom backgrounds for outline text fields and use EditText's background for the text field's outline.
The outline box styles previously didn't allow a custom drawable to be set. The box background was handled by TextInputLayout, which nulled out the EditText's background and drew the boxBackground directly to the canvas. That meant that a call to TextInputEditText#setBackground() would not actually do anything - it would result in the same outline text field.

In order to respect the background drawable, TextInputEditText's background is set to null in the style. Then, TextInputLayout programmatically sets the custom outline drawable if the background is already null. This avoids overwriting a drawable that may have already been set on the TextInputEditText.

This change does pretty much nothing to the filled box style; since the EditText's underline is still being used, the background of the EditText was never set to null for that style. This change should be a no-op for that style.

This move to using the EditText's background for the outline also improves the bounds of the outline text field and gets rid of the cutoff that was appearing at the top of the outline when TextInputLayout's hint was disabled and a hint was set on the EditText.

PiperOrigin-RevId: 230538561
2019-01-25 13:55:36 -05:00
cketcham
dc72aaeed4 Migrate Gradle build and sources to androidx
PiperOrigin-RevId: 225551505
2018-12-21 11:07:45 -05:00
afohrman
530a7a8f9e Automated g4 rollback of changelist 223552187
PiperOrigin-RevId: 223870917
2018-12-06 11:47:52 -05:00
afohrman
671f785662 Automated g4 rollback of changelist 223530191
PiperOrigin-RevId: 223552187
2018-12-06 11:42:22 -05:00
afohrman
ead212fbff Support shape theming in TextInputLayout.
PiperOrigin-RevId: 223530191
2018-12-06 11:41:19 -05:00
dniz
9ca33544ac Update package name to com.google.android.material
PiperOrigin-RevId: 193236235
2018-04-30 11:24:23 -04:00