Merge "Stop the snapping animation when we are there." into androidx-main
diff --git a/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppActivity.java b/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppActivity.java
index 5be75ab..b8ebfa5 100644
--- a/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppActivity.java
+++ b/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppActivity.java
@@ -162,19 +162,13 @@
.getInsets(WindowInsetsCompat.Type.systemBars()
| WindowInsetsCompat.Type.ime())
.toPlatformInsets();
- boolean insetsHandled = requireNonNull(mViewModel).updateWindowInsets(insets);
- if (insetsHandled) {
- // Insets are handled by the host. Only local content need padding.
- mActivityContainerView.setPadding(0, 0, 0, 0);
- mLocalContentContainerView.setPadding(insets.left, insets.top,
- insets.right, insets.bottom);
- } else {
- // Insets are handled locally, padding is applied at the top level.
- mActivityContainerView.setPadding(insets.left, insets.top,
- insets.right, insets.bottom);
- mLocalContentContainerView.setPadding(0, 0, 0, 0);
- }
+ requireNonNull(mViewModel).updateWindowInsets(insets);
+
+ // Insets are handled by the host. Only local content need padding.
+ mActivityContainerView.setPadding(0, 0, 0, 0);
+ mLocalContentContainerView.setPadding(insets.left, insets.top,
+ insets.right, insets.bottom);
return WindowInsetsCompat.CONSUMED.toWindowInsets();
}
diff --git a/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppViewModel.java b/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppViewModel.java
index 28cce46..9b64f77 100644
--- a/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppViewModel.java
+++ b/car/app/app-automotive/src/main/java/androidx/car/app/activity/CarAppViewModel.java
@@ -28,16 +28,12 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.annotation.OptIn;
import androidx.annotation.RestrictTo;
import androidx.annotation.VisibleForTesting;
-import androidx.car.app.HandshakeInfo;
import androidx.car.app.activity.renderer.ICarAppActivity;
import androidx.car.app.activity.renderer.IInsetsListener;
import androidx.car.app.activity.renderer.IRendererCallback;
-import androidx.car.app.annotations.ExperimentalCarApi;
import androidx.car.app.utils.ThreadUtils;
-import androidx.car.app.versioning.CarAppApiLevels;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
@@ -238,32 +234,22 @@
* Updates the insets for this {@link CarAppActivity}
*
* @param insets latest received {@link Insets}
- * @return true if this insets will be consumed by the host. Otherwise, the insets should be
- * consumed by the client.
*/
- public boolean updateWindowInsets(@NonNull Insets insets) {
+ public void updateWindowInsets(@NonNull Insets insets) {
if (!Objects.equals(mInsets, insets)) {
mInsets = insets;
- dispatchInsetsUpdates();
+ // If listener is not set yet, the inset will be dispatched once the listener is set.
+ if (mIInsetsListener != null) {
+ dispatchInsetsUpdates();
+ }
}
- return isHostHandlingInsets();
- }
-
- @OptIn(markerClass = ExperimentalCarApi.class)
- private boolean isHostHandlingInsets() {
- HandshakeInfo handshakeInfo = mServiceConnectionManager.getHandshakeInfo();
- return mIInsetsListener != null
- && handshakeInfo != null
- && handshakeInfo.getHostCarAppApiLevel() >= CarAppApiLevels.LEVEL_4;
}
@SuppressWarnings("NullAway")
private void dispatchInsetsUpdates() {
- if (isHostHandlingInsets()) {
- getServiceDispatcher().dispatch("onInsetsChanged",
- () -> requireNonNull(mIInsetsListener).onInsetsChanged(mInsets)
- );
- }
+ getServiceDispatcher().dispatch("onInsetsChanged",
+ () -> requireNonNull(mIInsetsListener).onInsetsChanged(mInsets)
+ );
}
/**
diff --git a/car/app/app-automotive/src/test/java/androidx/car/app/activity/CarAppActivityTest.java b/car/app/app-automotive/src/test/java/androidx/car/app/activity/CarAppActivityTest.java
index aca3558..539a2e8 100644
--- a/car/app/app-automotive/src/test/java/androidx/car/app/activity/CarAppActivityTest.java
+++ b/car/app/app-automotive/src/test/java/androidx/car/app/activity/CarAppActivityTest.java
@@ -353,34 +353,6 @@
}
@Test
- public void testWindowInsetsHandledLocallyWhenHostIsNotCapable() {
- setupCarAppActivityForTesting();
- try (ActivityScenario<CarAppActivity> scenario = ActivityScenario.launch(
- CarAppActivity.class)) {
- scenario.onActivity(activity -> {
- View activityContainer = activity.mActivityContainerView;
- View localContentContainer = activity.mLocalContentContainerView;
- Insets systemWindowInsets = Insets.of(10, 20, 30, 40);
- WindowInsets windowInsets = new WindowInsetsCompat.Builder()
- .setInsets(WindowInsetsCompat.Type.systemBars(), systemWindowInsets)
- .build()
- .toWindowInsets();
- activityContainer.onApplyWindowInsets(windowInsets);
-
- // Verify that the insets are handled locally
- assertThat(activityContainer.getPaddingBottom()).isEqualTo(40);
- assertThat(activityContainer.getPaddingTop()).isEqualTo(20);
- assertThat(activityContainer.getPaddingLeft()).isEqualTo(10);
- assertThat(activityContainer.getPaddingRight()).isEqualTo(30);
- assertThat(localContentContainer.getPaddingBottom()).isEqualTo(0);
- assertThat(localContentContainer.getPaddingTop()).isEqualTo(0);
- assertThat(localContentContainer.getPaddingLeft()).isEqualTo(0);
- assertThat(localContentContainer.getPaddingRight()).isEqualTo(0);
- });
- }
- }
-
- @Test
public void testWindowInsetsHandledRemotelyWhenHostIsCapable() {
setupCarAppActivityForTesting();
try (ActivityScenario<CarAppActivity> scenario = ActivityScenario.launch(
diff --git a/compose/ui/ui/api/current.ignore b/compose/ui/ui/api/current.ignore
index 57811ff..f3e8b53 100644
--- a/compose/ui/ui/api/current.ignore
+++ b/compose/ui/ui/api/current.ignore
@@ -1,3 +1,5 @@
// Baseline format: 1.0
RemovedClass: androidx.compose.ui.input.nestedscroll.NestedScrollDelegatingWrapperKt:
Removed class androidx.compose.ui.input.nestedscroll.NestedScrollDelegatingWrapperKt
+RemovedClass: androidx.compose.ui.platform.TextToolbarKt:
+ Removed class androidx.compose.ui.platform.TextToolbarKt
diff --git a/compose/ui/ui/api/current.txt b/compose/ui/ui/api/current.txt
index 73a4a63..fcb0bca 100644
--- a/compose/ui/ui/api/current.txt
+++ b/compose/ui/ui/api/current.txt
@@ -2350,9 +2350,6 @@
property public abstract androidx.compose.ui.platform.TextToolbarStatus status;
}
- public final class TextToolbarKt {
- }
-
public enum TextToolbarStatus {
enum_constant public static final androidx.compose.ui.platform.TextToolbarStatus Hidden;
enum_constant public static final androidx.compose.ui.platform.TextToolbarStatus Shown;
diff --git a/compose/ui/ui/api/public_plus_experimental_current.txt b/compose/ui/ui/api/public_plus_experimental_current.txt
index f5e9eb9..9dd1244 100644
--- a/compose/ui/ui/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui/api/public_plus_experimental_current.txt
@@ -2530,9 +2530,6 @@
property public abstract androidx.compose.ui.platform.TextToolbarStatus status;
}
- public final class TextToolbarKt {
- }
-
public enum TextToolbarStatus {
enum_constant public static final androidx.compose.ui.platform.TextToolbarStatus Hidden;
enum_constant public static final androidx.compose.ui.platform.TextToolbarStatus Shown;
diff --git a/compose/ui/ui/api/restricted_current.ignore b/compose/ui/ui/api/restricted_current.ignore
index 57811ff..f3e8b53 100644
--- a/compose/ui/ui/api/restricted_current.ignore
+++ b/compose/ui/ui/api/restricted_current.ignore
@@ -1,3 +1,5 @@
// Baseline format: 1.0
RemovedClass: androidx.compose.ui.input.nestedscroll.NestedScrollDelegatingWrapperKt:
Removed class androidx.compose.ui.input.nestedscroll.NestedScrollDelegatingWrapperKt
+RemovedClass: androidx.compose.ui.platform.TextToolbarKt:
+ Removed class androidx.compose.ui.platform.TextToolbarKt
diff --git a/compose/ui/ui/api/restricted_current.txt b/compose/ui/ui/api/restricted_current.txt
index 6f376a0..282f705 100644
--- a/compose/ui/ui/api/restricted_current.txt
+++ b/compose/ui/ui/api/restricted_current.txt
@@ -2386,9 +2386,6 @@
property public abstract androidx.compose.ui.platform.TextToolbarStatus status;
}
- public final class TextToolbarKt {
- }
-
public enum TextToolbarStatus {
enum_constant public static final androidx.compose.ui.platform.TextToolbarStatus Hidden;
enum_constant public static final androidx.compose.ui.platform.TextToolbarStatus Shown;
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidTextToolbar.android.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidTextToolbar.android.kt
index 940c607..6af5471 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidTextToolbar.android.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidTextToolbar.android.kt
@@ -37,10 +37,10 @@
override fun showMenu(
rect: Rect,
- onCopyRequested: ActionCallback?,
- onPasteRequested: ActionCallback?,
- onCutRequested: ActionCallback?,
- onSelectAllRequested: ActionCallback?
+ onCopyRequested: (() -> Unit)?,
+ onPasteRequested: (() -> Unit)?,
+ onCutRequested: (() -> Unit)?,
+ onSelectAllRequested: (() -> Unit)?
) {
textActionModeCallback.rect = rect
textActionModeCallback.onCopyRequested = onCopyRequested
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/actionmodecallback/TextActionModeCallback.android.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/actionmodecallback/TextActionModeCallback.android.kt
index d2318f0..c5d782e 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/actionmodecallback/TextActionModeCallback.android.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/actionmodecallback/TextActionModeCallback.android.kt
@@ -20,7 +20,6 @@
import android.view.Menu
import android.view.MenuItem
import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.platform.ActionCallback
internal const val MENU_ITEM_COPY = 0
internal const val MENU_ITEM_PASTE = 1
@@ -29,10 +28,10 @@
internal class TextActionModeCallback(
var rect: Rect = Rect.Zero,
- var onCopyRequested: ActionCallback? = null,
- var onPasteRequested: ActionCallback? = null,
- var onCutRequested: ActionCallback? = null,
- var onSelectAllRequested: ActionCallback? = null
+ var onCopyRequested: (() -> Unit)? = null,
+ var onPasteRequested: (() -> Unit)? = null,
+ var onCutRequested: (() -> Unit)? = null,
+ var onSelectAllRequested: (() -> Unit)? = null
) {
fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
requireNotNull(menu)
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TextToolbar.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TextToolbar.kt
index cd994e99..c9ba2b5 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TextToolbar.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TextToolbar.kt
@@ -18,7 +18,6 @@
import androidx.compose.ui.geometry.Rect
-internal typealias ActionCallback = () -> Unit
/**
* Interface for text-related toolbar.
*/
@@ -34,10 +33,10 @@
*/
fun showMenu(
rect: Rect,
- onCopyRequested: ActionCallback? = null,
- onPasteRequested: ActionCallback? = null,
- onCutRequested: ActionCallback? = null,
- onSelectAllRequested: ActionCallback? = null
+ onCopyRequested: (() -> Unit)? = null,
+ onPasteRequested: (() -> Unit)? = null,
+ onCutRequested: (() -> Unit)? = null,
+ onSelectAllRequested: (() -> Unit)? = null
)
/**
diff --git a/compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/DefaultTextToolbar.skiko.kt b/compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/DefaultTextToolbar.skiko.kt
index 7295336..def1d41 100644
--- a/compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/DefaultTextToolbar.skiko.kt
+++ b/compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/DefaultTextToolbar.skiko.kt
@@ -28,10 +28,10 @@
override fun showMenu(
rect: Rect,
- onCopyRequested: ActionCallback?,
- onPasteRequested: ActionCallback?,
- onCutRequested: ActionCallback?,
- onSelectAllRequested: ActionCallback?
+ onCopyRequested: (() -> Unit)?,
+ onPasteRequested: (() -> Unit)?,
+ onCutRequested: (() -> Unit)?,
+ onSelectAllRequested: (() -> Unit)?
) {
}
}
\ No newline at end of file
diff --git a/core/core/src/main/java/androidx/core/graphics/ColorUtils.java b/core/core/src/main/java/androidx/core/graphics/ColorUtils.java
index a7afe56..c30286e8 100644
--- a/core/core/src/main/java/androidx/core/graphics/ColorUtils.java
+++ b/core/core/src/main/java/androidx/core/graphics/ColorUtils.java
@@ -190,10 +190,10 @@
* have a contrast value of at least {@code minContrastRatio} when compared to
* {@code background}.
*
- * @param foreground the foreground color
- * @param background the opaque background color
+ * @param foreground the foreground color
+ * @param background the opaque background color
* @param minContrastRatio the minimum contrast ratio
- * @return the alpha value in the range 0-255, or -1 if no value could be calculated
+ * @return the alpha value in the range [0, 255] or -1 if no value could be calculated
*/
public static int calculateMinimumAlpha(@ColorInt int foreground, @ColorInt int background,
float minContrastRatio) {
@@ -238,14 +238,14 @@
/**
* Convert RGB components to HSL (hue-saturation-lightness).
* <ul>
- * <li>outHsl[0] is Hue [0 .. 360)</li>
- * <li>outHsl[1] is Saturation [0...1]</li>
- * <li>outHsl[2] is Lightness [0...1]</li>
+ * <li>outHsl[0] is Hue [0, 360)</li>
+ * <li>outHsl[1] is Saturation [0, 1]</li>
+ * <li>outHsl[2] is Lightness [0, 1]</li>
* </ul>
*
- * @param r red component value [0..255]
- * @param g green component value [0..255]
- * @param b blue component value [0..255]
+ * @param r red component value [0, 255]
+ * @param g green component value [0, 255]
+ * @param b blue component value [0, 255]
* @param outHsl 3-element array which holds the resulting HSL components
*/
public static void RGBToHSL(@IntRange(from = 0x0, to = 0xFF) int r,
@@ -290,12 +290,12 @@
/**
* Convert the ARGB color to its HSL (hue-saturation-lightness) components.
* <ul>
- * <li>outHsl[0] is Hue [0 .. 360)</li>
- * <li>outHsl[1] is Saturation [0...1]</li>
- * <li>outHsl[2] is Lightness [0...1]</li>
+ * <li>outHsl[0] is Hue [0, 360)</li>
+ * <li>outHsl[1] is Saturation [0, 1]</li>
+ * <li>outHsl[2] is Lightness [0, 1]</li>
* </ul>
*
- * @param color the ARGB color to convert. The alpha component is ignored
+ * @param color the ARGB color to convert. The alpha component is ignored
* @param outHsl 3-element array which holds the resulting HSL components
*/
public static void colorToHSL(@ColorInt int color, @NonNull float[] outHsl) {
@@ -305,9 +305,9 @@
/**
* Convert HSL (hue-saturation-lightness) components to a RGB color.
* <ul>
- * <li>hsl[0] is Hue [0 .. 360)</li>
- * <li>hsl[1] is Saturation [0...1]</li>
- * <li>hsl[2] is Lightness [0...1]</li>
+ * <li>hsl[0] is Hue [0, 360)</li>
+ * <li>hsl[1] is Saturation [0, 1]</li>
+ * <li>hsl[2] is Lightness [0, 1]</li>
* </ul>
* If hsv values are out of range, they are pinned.
*
@@ -384,7 +384,7 @@
/**
* Convert the ARGB color to its CIE Lab representative components.
*
- * @param color the ARGB color to convert. The alpha component is ignored
+ * @param color the ARGB color to convert. The alpha component is ignored
* @param outLab 3-element array which holds the resulting LAB components
*/
public static void colorToLAB(@ColorInt int color, @NonNull double[] outLab) {
@@ -395,14 +395,14 @@
* Convert RGB components to its CIE Lab representative components.
*
* <ul>
- * <li>outLab[0] is L [0 ...1)</li>
- * <li>outLab[1] is a [-128...127)</li>
- * <li>outLab[2] is b [-128...127)</li>
+ * <li>outLab[0] is L [0, 100]</li>
+ * <li>outLab[1] is a [-128, 127)</li>
+ * <li>outLab[2] is b [-128, 127)</li>
* </ul>
*
- * @param r red component value [0..255]
- * @param g green component value [0..255]
- * @param b blue component value [0..255]
+ * @param r red component value [0, 255]
+ * @param g green component value [0, 255]
+ * @param b blue component value [0, 255]
* @param outLab 3-element array which holds the resulting LAB components
*/
public static void RGBToLAB(@IntRange(from = 0x0, to = 0xFF) int r,
@@ -422,12 +422,12 @@
* 2° Standard Observer (1931).</p>
*
* <ul>
- * <li>outXyz[0] is X [0 ...95.047)</li>
- * <li>outXyz[1] is Y [0...100)</li>
- * <li>outXyz[2] is Z [0...108.883)</li>
+ * <li>outXyz[0] is X [0, 95.047)</li>
+ * <li>outXyz[1] is Y [0, 100)</li>
+ * <li>outXyz[2] is Z [0, 108.883)</li>
* </ul>
*
- * @param color the ARGB color to convert. The alpha component is ignored
+ * @param color the ARGB color to convert. The alpha component is ignored
* @param outXyz 3-element array which holds the resulting LAB components
*/
public static void colorToXYZ(@ColorInt int color, @NonNull double[] outXyz) {
@@ -441,14 +441,14 @@
* 2° Standard Observer (1931).</p>
*
* <ul>
- * <li>outXyz[0] is X [0 ...95.047)</li>
- * <li>outXyz[1] is Y [0...100)</li>
- * <li>outXyz[2] is Z [0...108.883)</li>
+ * <li>outXyz[0] is X [0, 95.047)</li>
+ * <li>outXyz[1] is Y [0, 100)</li>
+ * <li>outXyz[2] is Z [0, 108.883)</li>
* </ul>
*
- * @param r red component value [0..255]
- * @param g green component value [0..255]
- * @param b blue component value [0..255]
+ * @param r red component value [0, 255]
+ * @param g green component value [0, 255]
+ * @param b blue component value [0, 255]
* @param outXyz 3-element array which holds the resulting XYZ components
*/
public static void RGBToXYZ(@IntRange(from = 0x0, to = 0xFF) int r,
@@ -477,14 +477,14 @@
* 2° Standard Observer (1931).</p>
*
* <ul>
- * <li>outLab[0] is L [0 ...1)</li>
- * <li>outLab[1] is a [-128...127)</li>
- * <li>outLab[2] is b [-128...127)</li>
+ * <li>outLab[0] is L [0, 100]</li>
+ * <li>outLab[1] is a [-128, 127)</li>
+ * <li>outLab[2] is b [-128, 127)</li>
* </ul>
*
- * @param x X component value [0...95.047)
- * @param y Y component value [0...100)
- * @param z Z component value [0...108.883)
+ * @param x X component value [0, 95.047)
+ * @param y Y component value [0, 100)
+ * @param z Z component value [0, 108.883)
* @param outLab 3-element array which holds the resulting Lab components
*/
public static void XYZToLAB(@FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_X) double x,
@@ -509,14 +509,14 @@
* 2° Standard Observer (1931).</p>
*
* <ul>
- * <li>outXyz[0] is X [0 ...95.047)</li>
- * <li>outXyz[1] is Y [0...100)</li>
- * <li>outXyz[2] is Z [0...108.883)</li>
+ * <li>outXyz[0] is X [0, 95.047)</li>
+ * <li>outXyz[1] is Y [0, 100)</li>
+ * <li>outXyz[2] is Z [0, 108.883)</li>
* </ul>
*
- * @param l L component value [0...100)
- * @param a A component value [-128...127)
- * @param b B component value [-128...127)
+ * @param l L component value [0, 100]
+ * @param a A component value [-128, 127)
+ * @param b B component value [-128, 127)
* @param outXyz 3-element array which holds the resulting XYZ components
*/
public static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l,
@@ -545,9 +545,9 @@
* <p>This method expects the XYZ representation to use the D65 illuminant and the CIE
* 2° Standard Observer (1931).</p>
*
- * @param x X component value [0...95.047)
- * @param y Y component value [0...100)
- * @param z Z component value [0...108.883)
+ * @param x X component value [0, 95.047)
+ * @param y Y component value [0, 100)
+ * @param z Z component value [0, 108.883)
* @return int containing the RGB representation
*/
@ColorInt
@@ -571,9 +571,9 @@
/**
* Converts a color from CIE Lab to its RGB representation.
*
- * @param l L component value [0...100]
- * @param a A component value [-128...127]
- * @param b B component value [-128...127]
+ * @param l L component value [0, 100]
+ * @param a A component value [-128, 127]
+ * @param b B component value [-128, 127]
* @return int containing the RGB representation
*/
@ColorInt
@@ -619,7 +619,7 @@
*
* @param color1 the first ARGB color
* @param color2 the second ARGB color
- * @param ratio the blend ratio of {@code color1} to {@code color2}
+ * @param ratio the blend ratio of {@code color1} to {@code color2}
*/
@SuppressWarnings("unused")
@ColorInt
@@ -640,9 +640,9 @@
* <p>A blend ratio of 0.0 will result in {@code hsl1}, 0.5 will give an even blend,
* 1.0 will result in {@code hsl2}.</p>
*
- * @param hsl1 3-element array which holds the first HSL color
- * @param hsl2 3-element array which holds the second HSL color
- * @param ratio the blend ratio of {@code hsl1} to {@code hsl2}
+ * @param hsl1 3-element array which holds the first HSL color
+ * @param hsl2 3-element array which holds the second HSL color
+ * @param ratio the blend ratio of {@code hsl1} to {@code hsl2}
* @param outResult 3-element array which holds the resulting HSL components
*/
@SuppressWarnings("unused")
@@ -664,9 +664,9 @@
* <p>A blend ratio of 0.0 will result in {@code lab1}, 0.5 will give an even blend,
* 1.0 will result in {@code lab2}.</p>
*
- * @param lab1 3-element array which holds the first LAB color
- * @param lab2 3-element array which holds the second LAB color
- * @param ratio the blend ratio of {@code lab1} to {@code lab2}
+ * @param lab1 3-element array which holds the first LAB color
+ * @param lab2 3-element array which holds the second LAB color
+ * @param ratio the blend ratio of {@code lab1} to {@code lab2}
* @param outResult 3-element array which holds the resulting LAB components
*/
@SuppressWarnings("unused")
diff --git a/playground-common/playground.properties b/playground-common/playground.properties
index ff1bc3f..900309d 100644
--- a/playground-common/playground.properties
+++ b/playground-common/playground.properties
@@ -25,7 +25,7 @@
kotlin.code.style=official
# Disable docs
androidx.enableDocumentation=false
-androidx.playground.snapshotBuildId=8187875
+androidx.playground.snapshotBuildId=8241934
androidx.playground.metalavaBuildId=8073933
androidx.playground.dokkaBuildId=7472101
androidx.studio.type=playground
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacProcessingEnv.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacProcessingEnv.kt
index 685bf6b..25912f6 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacProcessingEnv.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacProcessingEnv.kt
@@ -284,9 +284,8 @@
return when (val enclosingElement = element.enclosingElement) {
is ExecutableElement -> {
val executableElement = wrapExecutableElement(enclosingElement)
-
executableElement.parameters.find { param ->
- param.element === element
+ param.element.simpleName == element.simpleName
} ?: error("Unable to create variable element for $element")
}
is TypeElement -> {
diff --git a/wear/compose/compose-material/api/current.txt b/wear/compose/compose-material/api/current.txt
index 607ec23..0c86c1c 100644
--- a/wear/compose/compose-material/api/current.txt
+++ b/wear/compose/compose-material/api/current.txt
@@ -245,11 +245,24 @@
@androidx.compose.runtime.Stable public interface PositionIndicatorState {
method public float getPositionFraction();
- method public int shouldShow(float scrollableContainerSizePx);
method public float sizeFraction(float scrollableContainerSizePx);
+ method public int visibility(float scrollableContainerSizePx);
property public abstract float positionFraction;
}
+ public final inline class PositionIndicatorVisibility {
+ ctor public PositionIndicatorVisibility();
+ }
+
+ public static final class PositionIndicatorVisibility.Companion {
+ method public int getAutoHide();
+ method public int getHide();
+ method public int getShow();
+ property public final int AutoHide;
+ property public final int Hide;
+ property public final int Show;
+ }
+
public final class ProgressIndicatorDefaults {
method public androidx.compose.animation.core.SpringSpec<java.lang.Float> getProgressAnimationSpec();
method public float getStrokeWidth();
@@ -409,19 +422,6 @@
public final class ShapesKt {
}
- public final inline class ShowResult {
- ctor public ShowResult();
- }
-
- public static final class ShowResult.Companion {
- method public int getAutoHide();
- method public int getHide();
- method public int getShow();
- property public final int AutoHide;
- property public final int Hide;
- property public final int Show;
- }
-
public final class SliderKt {
method @androidx.compose.runtime.Composable public static void InlineSlider(float value, kotlin.jvm.functions.Function1<? super java.lang.Float,kotlin.Unit> onValueChange, int steps, optional androidx.compose.ui.Modifier modifier, optional boolean enabled, optional kotlin.ranges.ClosedFloatingPointRange<java.lang.Float> valueRange, optional boolean segmented, optional kotlin.jvm.functions.Function0<kotlin.Unit> decreaseIcon, optional kotlin.jvm.functions.Function0<kotlin.Unit> increaseIcon, optional androidx.wear.compose.material.InlineSliderColors colors);
method @androidx.compose.runtime.Composable public static void InlineSlider(int value, kotlin.jvm.functions.Function1<? super java.lang.Integer,kotlin.Unit> onValueChange, optional androidx.compose.ui.Modifier modifier, optional boolean enabled, kotlin.ranges.IntProgression valueProgression, optional boolean segmented, optional kotlin.jvm.functions.Function0<kotlin.Unit> decreaseIcon, optional kotlin.jvm.functions.Function0<kotlin.Unit> increaseIcon, optional androidx.wear.compose.material.InlineSliderColors colors);
diff --git a/wear/compose/compose-material/api/public_plus_experimental_current.txt b/wear/compose/compose-material/api/public_plus_experimental_current.txt
index e071d94..1650eca 100644
--- a/wear/compose/compose-material/api/public_plus_experimental_current.txt
+++ b/wear/compose/compose-material/api/public_plus_experimental_current.txt
@@ -260,11 +260,24 @@
@androidx.compose.runtime.Stable public interface PositionIndicatorState {
method public float getPositionFraction();
- method public int shouldShow(float scrollableContainerSizePx);
method public float sizeFraction(float scrollableContainerSizePx);
+ method public int visibility(float scrollableContainerSizePx);
property public abstract float positionFraction;
}
+ public final inline class PositionIndicatorVisibility {
+ ctor public PositionIndicatorVisibility();
+ }
+
+ public static final class PositionIndicatorVisibility.Companion {
+ method public int getAutoHide();
+ method public int getHide();
+ method public int getShow();
+ property public final int AutoHide;
+ property public final int Hide;
+ property public final int Show;
+ }
+
public final class ProgressIndicatorDefaults {
method public androidx.compose.animation.core.SpringSpec<java.lang.Float> getProgressAnimationSpec();
method public float getStrokeWidth();
@@ -435,19 +448,6 @@
public final class ShapesKt {
}
- public final inline class ShowResult {
- ctor public ShowResult();
- }
-
- public static final class ShowResult.Companion {
- method public int getAutoHide();
- method public int getHide();
- method public int getShow();
- property public final int AutoHide;
- property public final int Hide;
- property public final int Show;
- }
-
public final class SliderKt {
method @androidx.compose.runtime.Composable public static void InlineSlider(float value, kotlin.jvm.functions.Function1<? super java.lang.Float,kotlin.Unit> onValueChange, int steps, optional androidx.compose.ui.Modifier modifier, optional boolean enabled, optional kotlin.ranges.ClosedFloatingPointRange<java.lang.Float> valueRange, optional boolean segmented, optional kotlin.jvm.functions.Function0<kotlin.Unit> decreaseIcon, optional kotlin.jvm.functions.Function0<kotlin.Unit> increaseIcon, optional androidx.wear.compose.material.InlineSliderColors colors);
method @androidx.compose.runtime.Composable public static void InlineSlider(int value, kotlin.jvm.functions.Function1<? super java.lang.Integer,kotlin.Unit> onValueChange, optional androidx.compose.ui.Modifier modifier, optional boolean enabled, kotlin.ranges.IntProgression valueProgression, optional boolean segmented, optional kotlin.jvm.functions.Function0<kotlin.Unit> decreaseIcon, optional kotlin.jvm.functions.Function0<kotlin.Unit> increaseIcon, optional androidx.wear.compose.material.InlineSliderColors colors);
diff --git a/wear/compose/compose-material/api/restricted_current.txt b/wear/compose/compose-material/api/restricted_current.txt
index 607ec23..0c86c1c 100644
--- a/wear/compose/compose-material/api/restricted_current.txt
+++ b/wear/compose/compose-material/api/restricted_current.txt
@@ -245,11 +245,24 @@
@androidx.compose.runtime.Stable public interface PositionIndicatorState {
method public float getPositionFraction();
- method public int shouldShow(float scrollableContainerSizePx);
method public float sizeFraction(float scrollableContainerSizePx);
+ method public int visibility(float scrollableContainerSizePx);
property public abstract float positionFraction;
}
+ public final inline class PositionIndicatorVisibility {
+ ctor public PositionIndicatorVisibility();
+ }
+
+ public static final class PositionIndicatorVisibility.Companion {
+ method public int getAutoHide();
+ method public int getHide();
+ method public int getShow();
+ property public final int AutoHide;
+ property public final int Hide;
+ property public final int Show;
+ }
+
public final class ProgressIndicatorDefaults {
method public androidx.compose.animation.core.SpringSpec<java.lang.Float> getProgressAnimationSpec();
method public float getStrokeWidth();
@@ -409,19 +422,6 @@
public final class ShapesKt {
}
- public final inline class ShowResult {
- ctor public ShowResult();
- }
-
- public static final class ShowResult.Companion {
- method public int getAutoHide();
- method public int getHide();
- method public int getShow();
- property public final int AutoHide;
- property public final int Hide;
- property public final int Show;
- }
-
public final class SliderKt {
method @androidx.compose.runtime.Composable public static void InlineSlider(float value, kotlin.jvm.functions.Function1<? super java.lang.Float,kotlin.Unit> onValueChange, int steps, optional androidx.compose.ui.Modifier modifier, optional boolean enabled, optional kotlin.ranges.ClosedFloatingPointRange<java.lang.Float> valueRange, optional boolean segmented, optional kotlin.jvm.functions.Function0<kotlin.Unit> decreaseIcon, optional kotlin.jvm.functions.Function0<kotlin.Unit> increaseIcon, optional androidx.wear.compose.material.InlineSliderColors colors);
method @androidx.compose.runtime.Composable public static void InlineSlider(int value, kotlin.jvm.functions.Function1<? super java.lang.Integer,kotlin.Unit> onValueChange, optional androidx.compose.ui.Modifier modifier, optional boolean enabled, kotlin.ranges.IntProgression valueProgression, optional boolean segmented, optional kotlin.jvm.functions.Function0<kotlin.Unit> decreaseIcon, optional kotlin.jvm.functions.Function0<kotlin.Unit> increaseIcon, optional androidx.wear.compose.material.InlineSliderColors colors);
diff --git a/wear/compose/compose-material/samples/src/main/java/androidx/wear/compose/material/samples/ScalingLazyColumnSample.kt b/wear/compose/compose-material/samples/src/main/java/androidx/wear/compose/material/samples/ScalingLazyColumnSample.kt
index 542f964..f38a020 100644
--- a/wear/compose/compose-material/samples/src/main/java/androidx/wear/compose/material/samples/ScalingLazyColumnSample.kt
+++ b/wear/compose/compose-material/samples/src/main/java/androidx/wear/compose/material/samples/ScalingLazyColumnSample.kt
@@ -103,7 +103,8 @@
Chip(
onClick = {
coroutineScope.launch {
- state.animateScrollToItem(it, scrollOffset)
+ // Add +1 to allow for the ListHeader
+ state.animateScrollToItem(it + 1, scrollOffset)
}
},
label = { Text("List item $it") },
diff --git a/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/PositionIndicator.kt b/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/PositionIndicator.kt
index 00a2e05..ab2f309a 100644
--- a/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/PositionIndicator.kt
+++ b/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/PositionIndicator.kt
@@ -36,6 +36,7 @@
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
+import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -68,22 +69,22 @@
* or hidden after a small delay.
*/
@Suppress("INLINE_CLASS_DEPRECATED")
-public inline class ShowResult internal constructor(internal val value: Int) {
+public inline class PositionIndicatorVisibility internal constructor(internal val value: Int) {
companion object {
/**
* Show the Position Indicator.
*/
- val Show = ShowResult(1)
+ val Show = PositionIndicatorVisibility(1)
/**
* Hide the Position Indicator.
*/
- val Hide = ShowResult(2)
+ val Hide = PositionIndicatorVisibility(2)
/**
- * Hide the Position Indicator after 2 seconds.
+ * Hide the Position Indicator after a short delay.
*/
- val AutoHide = ShowResult(3)
+ val AutoHide = PositionIndicatorVisibility(3)
}
}
@@ -130,7 +131,7 @@
* in pixels depending on orientation of the indicator, (height for vertical, width for
* horizontal)
*/
- fun shouldShow(scrollableContainerSizePx: Float): ShowResult
+ fun visibility(scrollableContainerSizePx: Float): PositionIndicatorVisibility
}
/**
@@ -294,14 +295,22 @@
val isScreenRound = isRoundDevice()
val actuallyVisible = remember { mutableStateOf(false) }
- val indicatorPosition = if (reverseDirection) {
- 1 - state.positionFraction
- } else {
- state.positionFraction
- }
var containerHeight by remember { mutableStateOf(1f) }
- val indicatorSize = state.sizeFraction(containerHeight)
- val displayState = DisplayState(indicatorPosition, indicatorSize)
+
+ val displayState by remember {
+ derivedStateOf {
+ val indicatorPosition = if (reverseDirection) {
+ 1 - state.positionFraction
+ } else {
+ state.positionFraction
+ }
+
+ DisplayState(
+ indicatorPosition,
+ state.sizeFraction(containerHeight)
+ )
+ }
+ }
val highlightAlpha = remember { Animatable(0f) }
val animatedDisplayState = customAnimateValueAsState(
@@ -330,10 +339,11 @@
}
}
- when (state.shouldShow(containerHeight)) {
- ShowResult.Show -> actuallyVisible.value = true
- ShowResult.Hide -> actuallyVisible.value = false
- ShowResult.AutoHide -> if (actuallyVisible.value) {
+ val visibility by remember { derivedStateOf { state.visibility(containerHeight) } }
+ when (visibility) {
+ PositionIndicatorVisibility.Show -> actuallyVisible.value = true
+ PositionIndicatorVisibility.Hide -> actuallyVisible.value = false
+ PositionIndicatorVisibility.AutoHide -> if (actuallyVisible.value) {
LaunchedEffect(true) {
delay(2000)
actuallyVisible.value = false
@@ -433,7 +443,7 @@
internal class DisplayState(
val position: Float,
- val size: Float,
+ val size: Float
)
internal val DisplayStateTwoWayConverter: TwoWayConverter<DisplayState, AnimationVector2D> =
@@ -468,7 +478,7 @@
override fun hashCode(): Int = fraction().hashCode()
- override fun shouldShow(scrollableContainerSizePx: Float) = ShowResult.Show
+ override fun visibility(scrollableContainerSizePx: Float) = PositionIndicatorVisibility.Show
}
/**
@@ -496,12 +506,12 @@
scrollableContainerSizePx / (scrollableContainerSizePx + scrollState.maxValue)
}
- override fun shouldShow(scrollableContainerSizePx: Float) = if (scrollState.maxValue == 0) {
- ShowResult.Hide
+ override fun visibility(scrollableContainerSizePx: Float) = if (scrollState.maxValue == 0) {
+ PositionIndicatorVisibility.Hide
} else if (scrollState.isScrollInProgress) {
- ShowResult.Show
+ PositionIndicatorVisibility.Show
} else {
- ShowResult.AutoHide
+ PositionIndicatorVisibility.AutoHide
}
override fun equals(other: Any?): Boolean {
@@ -557,7 +567,7 @@
state.layoutInfo.totalItemsCount.toFloat()
}
- override fun shouldShow(scrollableContainerSizePx: Float): ShowResult {
+ override fun visibility(scrollableContainerSizePx: Float): PositionIndicatorVisibility {
val canScroll = state.layoutInfo.visibleItemsInfo.isNotEmpty() && run {
val firstItem = state.layoutInfo.visibleItemsInfo.first()
val lastItem = state.layoutInfo.visibleItemsInfo.last()
@@ -568,9 +578,13 @@
lastItemEndOffset > scrollableContainerSizePx
}
return if (canScroll) {
- if (state.isScrollInProgress) ShowResult.Show else ShowResult.AutoHide
+ if (state.isScrollInProgress) {
+ PositionIndicatorVisibility.Show
+ } else {
+ PositionIndicatorVisibility.AutoHide
+ }
} else {
- ShowResult.Hide
+ PositionIndicatorVisibility.Hide
}
}
@@ -674,11 +688,15 @@
state.layoutInfo.totalItemsCount.toFloat()
}
- override fun shouldShow(scrollableContainerSizePx: Float): ShowResult {
+ override fun visibility(scrollableContainerSizePx: Float): PositionIndicatorVisibility {
return if (sizeFraction(scrollableContainerSizePx) < 0.999f) {
- if (state.isScrollInProgress) ShowResult.Show else ShowResult.AutoHide
+ if (state.isScrollInProgress) {
+ PositionIndicatorVisibility.Show
+ } else {
+ PositionIndicatorVisibility.AutoHide
+ }
} else {
- ShowResult.Hide
+ PositionIndicatorVisibility.Hide
}
}
diff --git a/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ToggleChip.kt b/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ToggleChip.kt
index d24f744..3acb401 100644
--- a/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ToggleChip.kt
+++ b/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ToggleChip.kt
@@ -65,13 +65,13 @@
import androidx.compose.ui.unit.dp
/**
- * A [ToggleChip] is a specialized type of [Chip] that includes a slot for a bi-state toggle icon
+ * A [ToggleChip] is a specialized type of [Chip] that includes a slot for a bi-state toggle control
* such as a radio button, toggle or checkbox.
*
* The Wear Material [ToggleChip] offers four slots and a specific layout for an application icon, a
- * label, a secondaryLabel and toggle icon. The application icon and secondaryLabel are optional.
+ * label, a secondaryLabel and toggle control. The application icon and secondaryLabel are optional.
* The items are laid out in a row with the optional icon at the start, a column containing the two
- * label slots in the middle and a slot for the toggle icons at the end.
+ * label slots in the middle and a slot for the toggle control at the end.
*
* The [ToggleChip] is Stadium shaped and has a max height designed to take no more than
* two lines of text of [Typography.button] style.
@@ -95,7 +95,7 @@
* @param modifier Modifier to be applied to the chip
* @param toggleControl A slot for providing the chip's toggle controls(s). The contents are
* expected to be a horizontally and vertically centre aligned icon of size
- * [ToggleChipDefaults.IconSize]. Three built-in types of toggle icon are supported and can be
+ * [ToggleChipDefaults.IconSize]. Three built-in types of toggle control are supported and can be
* obtained from [ToggleChipDefaults.SwitchIcon], [ToggleChipDefaults.RadioIcon] and
* [ToggleChipDefaults.CheckboxIcon]. In order to correctly render when the Chip is not enabled the
* icon must set its alpha value to [LocalContentAlpha].
@@ -235,26 +235,26 @@
* [ToggleChip] by having two "tappable" areas, one clickable and one toggleable.
*
* The Wear Material [SplitToggleChip] offers three slots and a specific layout for a label,
- * secondaryLabel and toggle icon. The secondaryLabel is optional. The items are laid out
- * with a column containing the two label slots and a slot for the toggle icon at the
+ * secondaryLabel and toggle control. The secondaryLabel is optional. The items are laid out
+ * with a column containing the two label slots and a slot for the toggle control at the
* end.
*
* A [SplitToggleChip] has two tappable areas, one tap area for the labels and another for the
* toggle control. The [onClick] listener will be associated with the main body of the split toggle
- * chip with the [onCheckedChange] listener associated with the toggle icon area only.
+ * chip with the [onCheckedChange] listener associated with the toggle control area only.
*
- * For a split toggle chip the background of the tappable background area behind the toggle icon
+ * For a split toggle chip the background of the tappable background area behind the toggle control
* will have a visual effect applied to provide a "divider" between the two tappable areas.
*
* The [SplitToggleChip] is Stadium shaped and has a max height designed to take no more than
* two lines of text of [Typography.button] style.
*
- * The recommended set of [ToggleChipColors] can be obtained from
+ * The recommended set of [SplitToggleChipColors] can be obtained from
* [ToggleChipDefaults], e.g. [ToggleChipDefaults.splitToggleChipColors].
*
* Chips can be enabled or disabled. A disabled chip will not respond to click events.
*
- * Example of a [SplitToggleChip] with a label and the toggle icon changed to checkbox:
+ * Example of a [SplitToggleChip] with a label and the toggle control changed to checkbox:
* @sample androidx.wear.compose.material.samples.SplitToggleChipWithCheckbox
*
* For more information, see the
@@ -271,14 +271,14 @@
* @param modifier Modifier to be applied to the chip
* @param toggleControl A slot for providing the chip's toggle controls(s). The contents are
* expected to be a horizontally and vertically centre aligned icon of size
- * [ToggleChipDefaults.IconSize]. Three built-in types of toggle icon are supported and can be
+ * [ToggleChipDefaults.IconSize]. Three built-in types of toggle control are supported and can be
* obtained from [ToggleChipDefaults.SwitchIcon], [ToggleChipDefaults.RadioIcon] and
* [ToggleChipDefaults.CheckboxIcon]. In order to correctly render when the Chip is not enabled the
* icon must set its alpha value to [LocalContentAlpha].
* @param secondaryLabel A slot for providing the chip's secondary label. The contents are expected
* to be "start" or "center" aligned. label and secondaryLabel contents should be consistently
* aligned.
- * @param colors [ToggleChipColors] that will be used to resolve the background and
+ * @param colors [SplitToggleChipColors] that will be used to resolve the background and
* content color for this chip in different states, see
* [ToggleChipDefaults.splitToggleChipColors].
* @param enabled Controls the enabled state of the chip. When `false`, this chip will not
@@ -472,8 +472,8 @@
public fun secondaryContentColor(enabled: Boolean, checked: Boolean): State<Color>
/**
- * Represents the icon tint color for the toggle icon for this chip, depending on the [enabled]
- * and [checked]properties.
+ * Represents the icon tint color for the toggle control for this chip, depending on the
+ * [enabled] and [checked]properties.
*
* @param enabled Whether the chip is enabled
* @param checked Whether the chip is currently checked/selected or unchecked/not selected
@@ -512,8 +512,8 @@
public fun secondaryContentColor(enabled: Boolean): State<Color>
/**
- * Represents the icon tint color for the toggle icon for this chip, depending on the [enabled]
- * and [checked]properties.
+ * Represents the icon tint color for the toggle control for this chip, depending on the
+ * [enabled] and [checked]properties.
*
* @param enabled Whether the chip is enabled
* @param checked Whether the chip is currently checked/selected or unchecked/not selected
@@ -524,7 +524,7 @@
/**
* Represents the overlay to apply to a split background SplitToggleChip to distinguish
* between the two tappable areas. The overlay will be applied to "lighten" the background of
- * area under the toggle icons, depending on the [enabled] and [checked] properties.
+ * area under the toggle control, depending on the [enabled] and [checked] properties.
*
* @param enabled Whether the chip is enabled
* @param checked Whether the chip is currently checked/selected or unchecked/not selected
@@ -534,7 +534,7 @@
}
/**
- * Contains the default values used by [ToggleChip]s
+ * Contains the default values used by [ToggleChip]s and [SplitToggleChip]s
*/
public object ToggleChipDefaults {
@@ -662,7 +662,7 @@
}
/**
- * Creates a [ToggleChipColors] for use in a [SplitToggleChip].
+ * Creates a [SplitToggleChipColors] for use in a [SplitToggleChip].
*
* @param backgroundColor The background color of this [SplitToggleChip] when enabled
* @param contentColor The content color of this [SplitToggleChip] when enabled.
@@ -724,7 +724,8 @@
)
/**
- * Creates switch style toggle [Icon]s for use in the toggleControl slot of a [ToggleChip].
+ * Creates switch style toggle [Icon]s for use in the toggleControl slot of a [ToggleChip] or
+ * [SplitToggleChip].
* Depending on [checked] will return either an 'on' (checked) or 'off' (unchecked) switch icon.
*
* @param checked whether the [ToggleChip] or [SplitToggleChip] is currently 'on' (checked/true)
@@ -751,7 +752,8 @@
}
/**
- * Creates a radio button style toggle [Icon]s for use in the toggleControl slot of a [ToggleChip].
+ * Creates a radio button style toggle [Icon]s for use in the toggleControl slot of a
+ * [ToggleChip] or [SplitToggleChip].
* Depending on [checked] will return either an 'on' (checked) or 'off' (unchecked) radio button
* icon.
*
@@ -768,7 +770,8 @@
}
/**
- * Creates a checkbox style toggle [Icon]s for use in the toggleControl slot of a [ToggleChip].
+ * Creates a checkbox style toggle [Icon]s for use in the toggleControl slot of a [ToggleChip]
+ * or [SplitToggleChip].
* Depending on [checked] will return either an 'on' (ticked/checked) or 'off'
* (unticked/unchecked) checkbox icon.
*
@@ -785,25 +788,27 @@
}
/**
- * The default height applied for the [ToggleChip].
- * Note that you can override it by applying Modifier.heightIn directly on [ToggleChip].
+ * The default height applied for the [ToggleChip] or [SplitToggleChip].
+ * Note that you can override it by applying Modifier.heightIn directly on [ToggleChip] or
+ * [SplitToggleChip].
*/
internal val Height = 52.dp
/**
- * The default size of app or toggle icons when used inside a [ToggleChip].
+ * The default size of app icons or toggle controls when used inside a [ToggleChip] or
+ * [SplitToggleChip].
*/
public val IconSize: Dp = 24.dp
/**
* The default size of the spacing between an icon and a text when they are used inside a
- * [ToggleChip].
+ * [ToggleChip] or [SplitToggleChip].
*/
internal val IconSpacing = 6.dp
/**
- * The default size of the spacing between a toggle icon and text when they are used
- * inside a [ToggleChip].
+ * The default size of the spacing between a toggle control and text when they are used
+ * inside a [ToggleChip] or [SplitToggleChip].
*/
internal val ToggleControlSpacing = 4.dp
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/CardDemo.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/CardDemo.kt
index f415848..b588367 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/CardDemo.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/CardDemo.kt
@@ -18,7 +18,6 @@
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
@@ -31,19 +30,17 @@
import androidx.wear.compose.material.Card
import androidx.wear.compose.material.CardDefaults
import androidx.wear.compose.material.MaterialTheme
-import androidx.wear.compose.material.ScalingLazyColumn
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TitleCard
@Composable
fun CardDemo() {
- ScalingLazyColumn(
+ ScalingLazyColumnWithRSB(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
space = 4.dp,
alignment = Alignment.CenterVertically
),
- contentPadding = PaddingValues(horizontal = 8.dp, vertical = 30.dp),
modifier = Modifier.fillMaxSize()
) {
item {
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ChipDemo.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ChipDemo.kt
index f2e9f71..efcd71b 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ChipDemo.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ChipDemo.kt
@@ -61,15 +61,9 @@
var enabled by remember { mutableStateOf(true) }
var chipStyle by remember { mutableStateOf(ChipStyle.Primary) }
- ScalingLazyColumn(
+ ScalingLazyColumnWithRSB(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically),
- contentPadding = PaddingValues(
- start = 8.dp,
- end = 8.dp,
- top = 15.dp,
- bottom = 50.dp
- )
) {
item {
Text(
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/DemoApp.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/DemoApp.kt
index 0aab880..b0591c3 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/DemoApp.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/DemoApp.kt
@@ -16,23 +16,33 @@
package androidx.wear.compose.integration.demos
+import android.annotation.SuppressLint
import androidx.compose.foundation.focusable
+import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollableDefaults
+import androidx.compose.foundation.gestures.ScrollableState
+import androidx.compose.foundation.gestures.scrollBy
+import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
+import androidx.compose.ui.composed
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.rotary.onRotaryScrollEvent
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.ExperimentalWearMaterialApi
@@ -51,6 +61,8 @@
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.rememberScalingLazyListState
import androidx.wear.compose.material.rememberSwipeToDismissBoxState
+import kotlinx.coroutines.channels.BufferOverflow
+import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
@Composable
@@ -180,6 +192,78 @@
return state
}
+@SuppressLint("ModifierInspectorInfo")
+@OptIn(ExperimentalComposeUiApi::class)
+@Suppress("ComposableModifierFactory")
+@Composable
+fun Modifier.rsbScroll(
+ scrollableState: ScrollableState,
+ flingBehavior: FlingBehavior,
+): Modifier {
+ val channel = remember { Channel<Float>(
+ capacity = 10,
+ onBufferOverflow = BufferOverflow.DROP_OLDEST
+ ) }
+ val focusRequester = remember { FocusRequester() }
+
+ var lastTimeNanos = remember { 0L }
+ var smoothSpeed = remember { 0f }
+ val speedWindowMillis = 200L
+
+ LaunchedEffect(Unit) {
+ focusRequester.requestFocus()
+ }
+
+ return composed {
+ var rsbScrollInProgress by remember { mutableStateOf(false) }
+ LaunchedEffect(rsbScrollInProgress) {
+ while (rsbScrollInProgress) {
+ withFrameNanos { nanos ->
+ val scrolledAmountPx = generateSequence {
+ channel.tryReceive().getOrNull()
+ }.sum()
+
+ val timeSinceLastFrameMillis = (nanos - lastTimeNanos) / 1_000_000
+ lastTimeNanos = nanos
+ if (scrolledAmountPx != 0f) {
+ // Speed is in pixels per second.
+ val speed = scrolledAmountPx * 1000 / timeSinceLastFrameMillis
+ val cappedElapsedTimeMillis =
+ timeSinceLastFrameMillis.coerceAtMost(speedWindowMillis)
+ smoothSpeed = ((speedWindowMillis - cappedElapsedTimeMillis) * speed +
+ cappedElapsedTimeMillis * smoothSpeed) / speedWindowMillis
+ launch {
+ scrollableState
+ .scrollBy(smoothSpeed * cappedElapsedTimeMillis / 1000)
+ }
+ } else if (smoothSpeed != 0f) {
+ rsbScrollInProgress = false
+ }
+ null // withFrameNanos wants a return value
+ }
+ }
+ if (smoothSpeed != 0f) {
+ val launchSpeed = smoothSpeed
+ smoothSpeed = 0f
+ launch {
+ scrollableState.scroll {
+ with(flingBehavior) {
+ performFling(launchSpeed)
+ }
+ }
+ }
+ }
+ }
+ this.onRotaryScrollEvent {
+ channel.trySend(it.verticalScrollPixels)
+ rsbScrollInProgress = true
+ true
+ }
+ .focusRequester(focusRequester)
+ .focusable()
+ }
+}
+
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun ScalingLazyColumnWithRSB(
@@ -189,30 +273,22 @@
reverseLayout: Boolean = false,
snap: Boolean = true,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
+ verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(space = 4.dp,
+ alignment = if (!reverseLayout) Alignment.Top else Alignment.Bottom
+ ),
content: ScalingLazyListScope.() -> Unit
) {
- val coroutineScope = rememberCoroutineScope()
- val focusRequester = remember { FocusRequester() }
+ val flingBehavior = if (snap) ScalingLazyColumnDefaults.snapFlingBehavior(
+ state = state
+ ) else ScrollableDefaults.flingBehavior()
ScalingLazyColumn(
- modifier = modifier
- .onRotaryScrollEvent {
- coroutineScope.launch {
- state.dispatchRawDelta(it.verticalScrollPixels)
- }
- true
- }
- .focusRequester(focusRequester)
- .focusable(),
+ modifier = modifier.rsbScroll(scrollableState = state, flingBehavior = flingBehavior),
state = state,
reverseLayout = reverseLayout,
scalingParams = scalingParams,
- flingBehavior = if (snap) ScalingLazyColumnDefaults.snapFlingBehavior(
- state = state
- ) else ScrollableDefaults.flingBehavior(),
+ flingBehavior = flingBehavior,
horizontalAlignment = horizontalAlignment,
+ verticalArrangement = verticalArrangement,
content = content
)
- LaunchedEffect(Unit) {
- focusRequester.requestFocus()
- }
}
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/PositionIndicatorDemos.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/PositionIndicatorDemos.kt
index 9ab33c2..fe7bfb6 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/PositionIndicatorDemos.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/PositionIndicatorDemos.kt
@@ -41,7 +41,7 @@
import androidx.wear.compose.material.PositionIndicatorState
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.ScalingLazyColumn
-import androidx.wear.compose.material.ShowResult
+import androidx.wear.compose.material.PositionIndicatorVisibility
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.rememberScalingLazyListState
@@ -145,7 +145,7 @@
get() = position.value
override fun sizeFraction(scrollableContainerSizePx: Float) = size.value
- override fun shouldShow(scrollableContainerSizePx: Float) = ShowResult.Show
+ override fun visibility(scrollableContainerSizePx: Float) = PositionIndicatorVisibility.Show
override fun equals(other: Any?) =
other is CustomPositionIndicatorState &&
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ProgressIndicatorDemo.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ProgressIndicatorDemo.kt
index ce91ad2..9817c4a 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ProgressIndicatorDemo.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ProgressIndicatorDemo.kt
@@ -13,7 +13,6 @@
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
@@ -42,7 +41,6 @@
import androidx.wear.compose.material.InlineSlider
import androidx.wear.compose.material.InlineSliderDefaults
import androidx.wear.compose.material.ProgressIndicatorDefaults
-import androidx.wear.compose.material.ScalingLazyColumn
import androidx.wear.compose.material.Text
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
@@ -84,14 +82,10 @@
val animatedProgress: Float by animateFloatAsState(targetValue = progress)
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
- ScalingLazyColumn(
+ ScalingLazyColumnWithRSB(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 8.dp),
- contentPadding = PaddingValues(
- top = 20.dp,
- bottom = 20.dp
- ),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/SliderDemo.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/SliderDemo.kt
index 6c26979..e91e256 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/SliderDemo.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/SliderDemo.kt
@@ -19,7 +19,6 @@
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
@@ -35,7 +34,6 @@
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.InlineSlider
import androidx.wear.compose.material.InlineSliderDefaults
-import androidx.wear.compose.material.ScalingLazyColumn
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.ToggleChip
import androidx.wear.compose.material.ToggleChipDefaults
@@ -46,13 +44,12 @@
var valueWithSegments by remember { mutableStateOf(2f) }
var enabled by remember { mutableStateOf(true) }
- ScalingLazyColumn(
+ ScalingLazyColumnWithRSB(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
space = 4.dp,
alignment = Alignment.CenterVertically
),
- contentPadding = PaddingValues(horizontal = 8.dp, vertical = 30.dp),
modifier = Modifier.fillMaxSize()
) {
item { Text("No segments, value = $valueWithoutSegments") }
@@ -91,13 +88,12 @@
var valueWithoutSegments by remember { mutableStateOf(5) }
var valueWithSegments by remember { mutableStateOf(2) }
- ScalingLazyColumn(
+ ScalingLazyColumnWithRSB(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
space = 4.dp,
alignment = Alignment.CenterVertically
),
- contentPadding = PaddingValues(horizontal = 8.dp, vertical = 30.dp),
modifier = Modifier.fillMaxSize()
) {
item { Text("No segments, value = $valueWithoutSegments") }
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ThemeDemo.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ThemeDemo.kt
index 5c5de0a..d6cb8d30 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ThemeDemo.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ThemeDemo.kt
@@ -30,12 +30,11 @@
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.MaterialTheme
-import androidx.wear.compose.material.ScalingLazyColumn
import androidx.wear.compose.material.Text
@Composable
fun ThemeFonts() {
- ScalingLazyColumn {
+ ScalingLazyColumnWithRSB {
item {
ThemeFontRow(style = MaterialTheme.typography.display1, description = "display1")
}
@@ -88,7 +87,7 @@
@Composable
fun ThemeColors() {
- ScalingLazyColumn {
+ ScalingLazyColumnWithRSB {
item {
ThemeColorRow(
backgroundColor = MaterialTheme.colors.background,
diff --git a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ToggleChipDemo.kt b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ToggleChipDemo.kt
index 941bafe..8e27c69 100644
--- a/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ToggleChipDemo.kt
+++ b/wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ToggleChipDemo.kt
@@ -17,13 +17,7 @@
package androidx.wear.compose.integration.demos
import android.widget.Toast
-import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.PaddingValues
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.rememberScrollState
-import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
@@ -31,7 +25,6 @@
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
@@ -39,11 +32,14 @@
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
+import androidx.wear.compose.material.ListHeader
import androidx.wear.compose.material.MaterialTheme
+import androidx.wear.compose.material.ScalingLazyListState
import androidx.wear.compose.material.SplitToggleChip
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.ToggleChip
import androidx.wear.compose.material.ToggleChipDefaults
+import androidx.wear.compose.material.rememberScalingLazyListState
@Composable
fun ToggleChips(
@@ -51,7 +47,7 @@
description: String = "Toggle Chips"
) {
val applicationContext = LocalContext.current
- val scrollState: ScrollState = rememberScrollState()
+ val scrollState: ScalingLazyListState = rememberScalingLazyListState()
var enabled by remember { mutableStateOf(true) }
var checkBoxIconChecked by remember { mutableStateOf(true) }
@@ -66,195 +62,235 @@
var switchIconWithIconChecked by remember { mutableStateOf(true) }
var splitWithCustomColorChecked by remember { mutableStateOf(true) }
- Column(
- modifier = Modifier.verticalScroll(scrollState)
- .padding(
- PaddingValues(
- start = 8.dp,
- end = 8.dp,
- top = 15.dp,
- bottom = 50.dp
- )
- ),
- verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically)
+ ScalingLazyColumnWithRSB(
+ state = scrollState,
+ verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically),
) {
- Text(
- text = description,
- modifier = Modifier.align(Alignment.CenterHorizontally),
- textAlign = TextAlign.Center,
- style = MaterialTheme.typography.caption1,
- color = Color.White
- )
- CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
- ToggleChip(
- label = { Text("CheckboxIcon") },
- checked = checkBoxIconChecked,
- toggleControl = {
- ToggleChipDefaults.CheckboxIcon(checked = checkBoxIconChecked)
- },
- onCheckedChange = { checkBoxIconChecked = it },
- enabled = enabled,
- )
- ToggleChip(
- label = { Text("SwitchIcon") },
- checked = switchIconChecked,
- toggleControl = {
- ToggleChipDefaults.SwitchIcon(checked = switchIconChecked)
- },
- onCheckedChange = { switchIconChecked = it },
- enabled = enabled,
- )
- ToggleChip(
- label = {
- Text("RadioIcon", maxLines = 2, overflow = TextOverflow.Ellipsis)
- },
- checked = radioIconChecked,
- toggleControl = {
- ToggleChipDefaults.RadioIcon(checked = radioIconChecked)
- },
- onCheckedChange = { radioIconChecked = it },
- enabled = enabled,
- )
- ToggleChip(
- label = {
- Text(
- "RadioIcon",
- maxLines = 1,
- overflow = TextOverflow.Ellipsis
- )
- },
- secondaryLabel = {
- Text("With secondary label", maxLines = 1, overflow = TextOverflow.Ellipsis)
- },
- checked = radioIconWithSecondaryChecked,
- toggleControl = {
- ToggleChipDefaults.RadioIcon(checked = radioIconWithSecondaryChecked)
- },
- onCheckedChange = { radioIconWithSecondaryChecked = it },
- enabled = enabled,
- )
- ToggleChip(
- label = {
- Text("SwitchIcon", maxLines = 1, overflow = TextOverflow.Ellipsis)
- },
- secondaryLabel = {
- Text("With secondary label", maxLines = 1, overflow = TextOverflow.Ellipsis)
- },
- checked = switchIconWithSecondaryChecked,
- toggleControl = {
- ToggleChipDefaults.SwitchIcon(checked = switchIconWithSecondaryChecked)
- },
- onCheckedChange = { switchIconWithSecondaryChecked = it },
- appIcon = { DemoIcon(R.drawable.ic_airplanemode_active_24px) },
- enabled = enabled,
- )
- ToggleChip(
- label = { Text("SwitchIcon", maxLines = 1, overflow = TextOverflow.Ellipsis) },
- secondaryLabel = {
- Text("With switchable icon", maxLines = 1, overflow = TextOverflow.Ellipsis)
- },
- checked = switchIconWithIconChecked,
- toggleControl = {
- ToggleChipDefaults.SwitchIcon(checked = switchIconWithIconChecked)
- },
- onCheckedChange = { switchIconWithIconChecked = it },
- appIcon = {
- if (switchIconWithIconChecked) DemoIcon(R.drawable.ic_volume_up_24px) else
- DemoIcon(R.drawable.ic_volume_off_24px)
- },
- enabled = enabled,
- )
- Text(
- text = "Split Toggle Chips",
- modifier = Modifier.align(Alignment.CenterHorizontally),
- textAlign = TextAlign.Center,
- style = MaterialTheme.typography.caption1,
- color = Color.White
- )
- SplitToggleChip(
- label = { Text("Split with CheckboxIcon") },
- checked = splitWithCheckboxIconChecked,
- toggleControl = {
- ToggleChipDefaults.CheckboxIcon(checked = splitWithCheckboxIconChecked)
- },
- onCheckedChange = { splitWithCheckboxIconChecked = it },
- onClick = {
- Toast.makeText(
- applicationContext, "Text was clicked",
- Toast.LENGTH_SHORT
- ).show()
- },
- enabled = enabled,
- )
- SplitToggleChip(
- label = { Text("Split with SwitchIcon") },
- checked = splitWithSwitchIconChecked,
- toggleControl = {
- ToggleChipDefaults.SwitchIcon(checked = splitWithSwitchIconChecked)
- },
- onCheckedChange = { splitWithSwitchIconChecked = it },
- onClick = {
- Toast.makeText(
- applicationContext, "Text was clicked",
- Toast.LENGTH_SHORT
- ).show()
- },
- enabled = enabled,
- )
- SplitToggleChip(
- label = { Text("Split with RadioIcon") },
- checked = splitWithRadioIconChecked,
- toggleControl = {
- ToggleChipDefaults.RadioIcon(checked = splitWithRadioIconChecked)
- },
- onCheckedChange = { splitWithRadioIconChecked = it },
- onClick = {
- Toast.makeText(
- applicationContext, "Text was clicked",
- Toast.LENGTH_SHORT
- ).show()
- },
- enabled = enabled,
- )
- SplitToggleChip(
- label = {
- Text(
- "Split with SwitchIcon", maxLines = 1,
- overflow = TextOverflow.Ellipsis
- )
- },
- secondaryLabel = {
- Text(
- "and custom color", maxLines = 1,
- overflow = TextOverflow.Ellipsis
- )
- },
- checked = splitWithCustomColorChecked,
- toggleControl = {
- ToggleChipDefaults.SwitchIcon(checked = splitWithCustomColorChecked)
- },
- onCheckedChange = { splitWithCustomColorChecked = it },
- onClick = {
- Toast.makeText(
- applicationContext,
- "Text was clicked", Toast.LENGTH_SHORT
- ).show()
- },
- colors = ToggleChipDefaults.splitToggleChipColors(
- checkedToggleControlTintColor = Color(161, 231, 176)
- ),
- enabled = enabled,
- )
- ToggleChip(
- checked = enabled,
- onCheckedChange = { enabled = it },
- label = {
- Text("Chips enabled")
- },
- toggleControl = {
- ToggleChipDefaults.SwitchIcon(checked = enabled)
- },
- )
+ item {
+ ListHeader {
+ Text(
+ text = description,
+ textAlign = TextAlign.Center,
+ style = MaterialTheme.typography.caption1,
+ color = Color.White
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ ToggleChip(
+ label = { Text("CheckboxIcon") },
+ checked = checkBoxIconChecked,
+ toggleControl = {
+ ToggleChipDefaults.CheckboxIcon(checked = checkBoxIconChecked)
+ },
+ onCheckedChange = { checkBoxIconChecked = it },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ ToggleChip(
+ label = { Text("SwitchIcon") },
+ checked = switchIconChecked,
+ toggleControl = {
+ ToggleChipDefaults.SwitchIcon(checked = switchIconChecked)
+ },
+ onCheckedChange = { switchIconChecked = it },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ ToggleChip(
+ label = {
+ Text("RadioIcon", maxLines = 2, overflow = TextOverflow.Ellipsis)
+ },
+ checked = radioIconChecked,
+ toggleControl = {
+ ToggleChipDefaults.RadioIcon(checked = radioIconChecked)
+ },
+ onCheckedChange = { radioIconChecked = it },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ ToggleChip(
+ label = {
+ Text(
+ "RadioIcon",
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ },
+ secondaryLabel = {
+ Text("With secondary label", maxLines = 1, overflow = TextOverflow.Ellipsis)
+ },
+ checked = radioIconWithSecondaryChecked,
+ toggleControl = {
+ ToggleChipDefaults.RadioIcon(checked = radioIconWithSecondaryChecked)
+ },
+ onCheckedChange = { radioIconWithSecondaryChecked = it },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ ToggleChip(
+ label = {
+ Text("SwitchIcon", maxLines = 1, overflow = TextOverflow.Ellipsis)
+ },
+ secondaryLabel = {
+ Text("With secondary label", maxLines = 1, overflow = TextOverflow.Ellipsis)
+ },
+ checked = switchIconWithSecondaryChecked,
+ toggleControl = {
+ ToggleChipDefaults.SwitchIcon(checked = switchIconWithSecondaryChecked)
+ },
+ onCheckedChange = { switchIconWithSecondaryChecked = it },
+ appIcon = { DemoIcon(R.drawable.ic_airplanemode_active_24px) },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ ToggleChip(
+ label = { Text("SwitchIcon", maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ secondaryLabel = {
+ Text("With switchable icon", maxLines = 1, overflow = TextOverflow.Ellipsis)
+ },
+ checked = switchIconWithIconChecked,
+ toggleControl = {
+ ToggleChipDefaults.SwitchIcon(checked = switchIconWithIconChecked)
+ },
+ onCheckedChange = { switchIconWithIconChecked = it },
+ appIcon = {
+ if (switchIconWithIconChecked) DemoIcon(R.drawable.ic_volume_up_24px) else
+ DemoIcon(R.drawable.ic_volume_off_24px)
+ },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ ListHeader {
+ Text(
+ text = "Split Toggle Chips",
+ textAlign = TextAlign.Center,
+ style = MaterialTheme.typography.caption1,
+ color = Color.White
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ SplitToggleChip(
+ label = { Text("Split with CheckboxIcon") },
+ checked = splitWithCheckboxIconChecked,
+ toggleControl = {
+ ToggleChipDefaults.CheckboxIcon(checked = splitWithCheckboxIconChecked)
+ },
+ onCheckedChange = { splitWithCheckboxIconChecked = it },
+ onClick = {
+ Toast.makeText(
+ applicationContext, "Text was clicked",
+ Toast.LENGTH_SHORT
+ ).show()
+ },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ SplitToggleChip(
+ label = { Text("Split with SwitchIcon") },
+ checked = splitWithSwitchIconChecked,
+ toggleControl = {
+ ToggleChipDefaults.SwitchIcon(checked = splitWithSwitchIconChecked)
+ },
+ onCheckedChange = { splitWithSwitchIconChecked = it },
+ onClick = {
+ Toast.makeText(
+ applicationContext, "Text was clicked",
+ Toast.LENGTH_SHORT
+ ).show()
+ },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ SplitToggleChip(
+ label = { Text("Split with RadioIcon") },
+ checked = splitWithRadioIconChecked,
+ toggleControl = {
+ ToggleChipDefaults.RadioIcon(checked = splitWithRadioIconChecked)
+ },
+ onCheckedChange = { splitWithRadioIconChecked = it },
+ onClick = {
+ Toast.makeText(
+ applicationContext, "Text was clicked",
+ Toast.LENGTH_SHORT
+ ).show()
+ },
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ SplitToggleChip(
+ label = {
+ Text(
+ "Split with SwitchIcon", maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ },
+ secondaryLabel = {
+ Text(
+ "and custom color", maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ },
+ checked = splitWithCustomColorChecked,
+ toggleControl = {
+ ToggleChipDefaults.SwitchIcon(checked = splitWithCustomColorChecked)
+ },
+ onCheckedChange = { splitWithCustomColorChecked = it },
+ onClick = {
+ Toast.makeText(
+ applicationContext,
+ "Text was clicked", Toast.LENGTH_SHORT
+ ).show()
+ },
+ colors = ToggleChipDefaults.splitToggleChipColors(
+ checkedToggleControlTintColor = Color(161, 231, 176)
+ ),
+ enabled = enabled,
+ )
+ }
+ }
+ item {
+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
+ ToggleChip(
+ checked = enabled,
+ onCheckedChange = { enabled = it },
+ label = {
+ Text("Chips enabled")
+ },
+ toggleControl = {
+ ToggleChipDefaults.SwitchIcon(checked = enabled)
+ },
+ )
+ }
}
}
}