Skip to content

Commit d7e75bb

Browse files
pubiqqleticiarossi
authored andcommittedSep 13, 2023
[Docs] Minor code block improvements
Resolves #3570 GIT_ORIGIN_REV_ID=ca0c9b122e669dd53ba4fbe1a06b3ec3e38ce58d PiperOrigin-RevId: 564766453
1 parent 5f2b4b2 commit d7e75bb

File tree

7 files changed

+46
-65
lines changed

7 files changed

+46
-65
lines changed
 

‎docs/components/BottomSheet.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ edge) if the navigation bar is transparent and `app:enableEdgeToEdge` is true.
208208
To enable edge-to-edge by default for modal bottom sheets, you can override
209209
`?attr/bottomSheetDialogTheme` like the below example:
210210

211-
```
211+
```xml
212212
<style name="AppTheme" parent="Theme.Material3.*">
213213
...
214214
<item name="bottomSheetDialogTheme">@style/ThemeOverlay.App.BottomSheetDialog</item>

‎docs/components/Carousel.md

+18-28
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Next, set your `RecyclerView`s layout manager to a new `CarouselLayoutManager`.
8686
android:clipToPadding="false" />
8787
```
8888

89-
```kotlin
89+
```kt
9090
carouselRecyclerView.setLayoutManager(CarouselLayoutManager())
9191
```
9292

@@ -114,7 +114,7 @@ by medium and small items, depending on the size of the `RecyclerView`
114114
container.
115115

116116
You can use the multi-browse strategy by passing in no arguments to the
117-
CarouselLayoutManager constructor: `new CarouselLayoutManager()`.
117+
CarouselLayoutManager constructor: `CarouselLayoutManager()`.
118118

119119
## Hero strategy
120120

@@ -140,14 +140,13 @@ carousels with `match_parent` as the width will have more and more large items
140140
as the screen size grows.
141141

142142
You can use the hero strategy by passing in the strategy to the
143-
CarouselLayoutManager constructor: `new CarouselLayoutManager(new
144-
HeroStrategy())`.
143+
CarouselLayoutManager constructor: `CarouselLayoutManager(HeroStrategy())`.
145144

146145
With the hero strategy, it is recommended to use the `CarouselSnapHelper` to snap to the nearest item like so:
147146

148-
```
149-
SnapHelper snapHelper = new CarouselSnapHelper();
150-
snapHelper.attachToRecyclerView(carouselRecyclerView);
147+
```kt
148+
val snapHelper = CarouselSnapHelper()
149+
snapHelper.attachToRecyclerView(carouselRecyclerView)
151150
```
152151

153152
## Fullscreen strategy
@@ -158,8 +157,8 @@ A fullscreen strategy shows one item at a time that takes up the entire space
158157
of the carousel.
159158

160159
You can use the fullscreen strategy by passing in the strategy to the
161-
CarouselLayoutManager constructor: `new CarouselLayoutManager(new
162-
FullScreenStrategy())`.
160+
CarouselLayoutManager constructor:
161+
`CarouselLayoutManager(FullScreenStrategy())`.
163162

164163
With the fullscreen strategy, it is recommended to use a vertical orientation
165164
carousel by either setting the orientation on the CarouselLayoutManager with the
@@ -171,17 +170,9 @@ landscape in order to maintain the aspect ratios of your images.
171170
It is also recommended to use the `CarouselSnapHelper`
172171
to snap to the nearest item like so:
173172

174-
```
175-
SnapHelper snapHelper = new CarouselSnapHelper();
176-
snapHelper.attachToRecyclerView(carouselRecyclerView);
177-
```
178-
179-
It is also recommended to use the `CarouselSnapHelper`
180-
to snap to the nearest item like so:
181-
182-
```
183-
SnapHelper snapHelper = new CarouselSnapHelper();
184-
snapHelper.attachToRecyclerView(carouselRecyclerView);
173+
```kt
174+
val snapHelper = CarouselSnapHelper()
175+
snapHelper.attachToRecyclerView(carouselRecyclerView)
185176
```
186177

187178
## Attributes
@@ -211,13 +202,12 @@ by setting an
211202
[`onMaskChangedListener`](https://developer.android.com/reference/com/google/android/material/carousel/OnMaskChangedListener)
212203
on your `MaskableFrameLayout` inside your `RecyclerView.ViewHolder`.
213204

214-
```kotlin
215-
(viewHolder.itemView as MaskableFrameLayout).setOnMaskChangedListener(
205+
```kt
206+
(viewHolder.itemView as MaskableFrameLayout).setOnMaskChangedListener {
216207
maskRect ->
217208
// Any custom motion to run when mask size changes
218-
viewHolder.title.setTranslationX(maskRect.left);
219-
viewHolder.title.setAlpha(lerp(1F, 0F, 0F, 80F, maskRect.left));
220-
);
209+
viewHolder.title.setTranslationX(maskRect.left)
210+
viewHolder.title.setAlpha(lerp(1F, 0F, 0F, 80F, maskRect.left))
221211
}
222212
```
223213

@@ -227,7 +217,7 @@ In the example above, a title is translated so it appears pinned to the left mas
227217

228218
You can control the alignment of the focal (large) items in the carousel by setting the `app:carousel_alignment` attribute on your RecyclerView, if you are also setting the RecyclerView's LayoutManager through `app:layoutManager`:
229219

230-
```
220+
```xml
231221
<androidx.recyclerview.widget.RecyclerView
232222
...
233223
app:layoutManager="com.google.android.material.carousel.CarouselLayoutManager"
@@ -237,8 +227,8 @@ You can control the alignment of the focal (large) items in the carousel by sett
237227

238228
If CarouselLayoutManager is being set programmatically, you may set the alignment as well programmatically:
239229

240-
```
241-
carouselLayoutManager.setCarouselAlignment(CarouselLayoutManager.CENTER);
230+
```kt
231+
carouselLayoutManager.setCarouselAlignment(CarouselLayoutManager.CENTER)
242232
```
243233

244234
By default, the focal alignment is start-aligned.

‎docs/components/DatePicker.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ To show the picker to the user:
117117

118118
Subscribe to button clicks or dismiss events with the following calls:
119119

120-
```
120+
```kt
121121
picker.addOnPositiveButtonClickListener {
122122
// Respond to positive button click.
123123
}

‎docs/components/TimePicker.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ time format you choose.
6060
You can use either `TimeFormat.CLOCK_12H` (1 ring) or `TimeFormat.CLOCK_24H` (2 rings),
6161
depending on the location of the device:
6262

63-
```
63+
```kt
6464
val isSystem24Hour = is24HourFormat(this)
6565
val clockFormat = if (isSystem24Hour) TimeFormat.CLOCK_24H else TimeFormat.CLOCK_12H
6666
```
@@ -88,7 +88,7 @@ To show the time picker to the user:
8888

8989
Subscribe to positive button click, negative button click, cancel and dismiss events with the following calls:
9090

91-
```
91+
```kt
9292
picker.addOnPositiveButtonClickListener {
9393
// call back code
9494
}

‎docs/components/TopAppBar.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,18 @@ background.
322322

323323
In code:
324324

325-
```
326-
appBarLayout.setStatusBarForeground(
327-
MaterialShapeDrawable.createWithElevationOverlay(getContext()));
325+
```kt
326+
appBarLayout.statusBarForeground =
327+
MaterialShapeDrawable.createWithElevationOverlay(context)
328328
```
329329

330330
Or if using Tonal Surface Colors instead of Elevation Overlays, you can simply
331331
set the `statusBarForeground` to `colorSurface` to let `AppBarLayout`
332332
automatically match the status bar color to its own background:
333333

334-
```
334+
```kt
335335
appBarLayout.setStatusBarForegroundColor(
336-
MaterialColors.getColor(appBarLayout, R.attr.colorSurface));
336+
MaterialColors.getColor(appBarLayout, R.attr.colorSurface))
337337
```
338338

339339
### Center aligned top app bar example

‎docs/theming/Color.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ activity can be seen below. Since we are overriding color resources in xml at
690690
runtime, make sure the method is invoked before you inflate the view to take
691691
effect.
692692

693-
```
693+
```java
694694
import com.google.android.material.color.DynamicColorsOptions;
695695
import com.google.android.material.color.DynamicColors;
696696

@@ -712,7 +712,7 @@ import com.google.android.material.color.DynamicColors;
712712
An example usage for applying content-based dynamic colors to a specific
713713
fragment/view:
714714

715-
```
715+
```java
716716
import com.google.android.material.color.DynamicColorsOptions;
717717
import com.google.android.material.color.DynamicColors;
718718

@@ -762,7 +762,7 @@ your branded or custom themes, we have created the following API in the
762762

763763
In your application class’ `onCreate()` method, call:
764764

765-
```
765+
```java
766766
ColorContrast.applyToActivitiesIfAvailable(
767767
this,
768768
new ColorContrastOptions.Builder()

‎docs/theming/Motion.md

+16-25
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Attribute | Default value | Description
4040

4141
To customize an easing value, override any of the attributes in your app’s theme to your own interpolator resource.
4242

43-
```
43+
```xml
4444
<style name="Theme.MyTheme" parent="Theme.Material3.DayNight.NoActionBar">
4545
....
4646
<item name="motionEasingEmphasizedInterpolator">@interpolator/my_app_emphasized_interpolator</item>
@@ -80,7 +80,7 @@ ensure your transitions have a consistent sense of speed.
8080
To override a duration attribute, assign the attribute to your desired
8181
millisecond integer value.
8282

83-
```
83+
```xml
8484
<style name="Theme.MyTheme" parent="Theme.Material3.DayNight.NoActionBar">
8585
....
8686
<item name="motionDurationLong2">450</item>
@@ -106,7 +106,7 @@ When implementing your own animations, use an easing and duration theme attribut
106106

107107
When creating animations in xml, set your animation's `interpolator` and `duration` properties to a Material motion theme attribute.
108108

109-
```
109+
```xml
110110
<!-- res/anim/slide_in.xml –>
111111
<set xmlns:android="http://schemas.android.com/apk/res/android"
112112
android:duration="?attr/motionEasingDurationMedium1"
@@ -122,28 +122,18 @@ When creating animations in xml, set your animation's `interpolator` and `durati
122122
123123
If creating animations in Java or Kotlin, Material provides a `MotionUtils` class to help facilitate loading `interpolator` and `duration` theme attributes.
124124
125-
```
126-
ValueAnimator animator = ValueAnimator.ofFloat(currentProgress, newProgress);
127-
animator.addUpdateListener(
128-
new AnimatorUpdateListener() {
129-
@Override
130-
public void onAnimationUpdate(ValueAnimator animation) {
131-
float progress = (float) animation.getAnimatedValue();
132-
myView.setAlpha(progress)
133-
setActiveIndicatorProgress(progress, newProgress);
134-
}
135-
});
136-
animatior.setInterpolator(
137-
MotionUtils.resolveThemeInterpolator(
138-
getContext(),
139-
R.attr.motionEasingStandardInterpolator, // easing theme attribute
140-
new FastOutSlowInInterpolator())); // default fallback interpolator
141-
animator.setDuration(
142-
MotionUtils.resolveThemeDuration(
143-
getContext(),
144-
R.attr.motionDurationLong1, // duration theme attribute
145-
500L)); // default fallback duration
146-
animator.start();
125+
```kt
126+
val interpolator = MotionUtils.resolveThemeInterpolator(
127+
context,
128+
R.attr.motionEasingStandardInterpolator, // interpolator theme attribute
129+
FastOutSlowInInterpolator() // default fallback interpolator
130+
)
131+
132+
val duration = MotionUtils.resolveThemeDuration(
133+
context,
134+
R.attr.motionDurationLong1, // duration theme attribute
135+
500 // default fallback duration
136+
)
147137
```
148138
149139
## Transitions
@@ -237,6 +227,7 @@ will be shared. Add a matching `transitionName` to each of these Views.
237227
android:id="@+id/start_view"
238228
android:transitionName="shared_element_container" />
239229
```
230+
240231
```xml
241232
<!--fragment_b.xml-->
242233
<View

0 commit comments

Comments
 (0)
Please sign in to comment.