Skip to content

Commit

Permalink
Update check your phone screen layout (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored Mar 18, 2024
1 parent b9e9860 commit d4694ae
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 102 deletions.
3 changes: 1 addition & 2 deletions auth/composables/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ package com.google.android.horologist.auth.composables.screens {
}

public final class CheckYourPhoneScreenKt {
method @androidx.compose.runtime.Composable public static void CheckYourPhoneScreen(optional androidx.compose.ui.Modifier modifier);
method @androidx.compose.runtime.Composable public static void CheckYourPhoneScreen(optional androidx.compose.ui.Modifier modifier, String message);
method @androidx.compose.runtime.Composable public static void CheckYourPhoneScreen(optional androidx.compose.ui.Modifier modifier, optional String? message);
}

public final class SelectAccountScreenKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.android.horologist.auth.composables.screens

import android.content.res.Configuration
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -39,52 +41,33 @@ import androidx.wear.compose.material.Text
import com.google.android.horologist.auth.composables.R
import com.google.android.horologist.compose.material.util.DECORATIVE_ELEMENT_CONTENT_DESCRIPTION

private const val TOP_PADDING_SCREEN_PERCENTAGE = 0.2
private const val TOP_PADDING_SCREEN_PERCENTAGE = 0.1248f
private const val BOTTOM_PADDING_SCREEN_PERCENTAGE = 0.0624f
private const val SIDE_PADDING_SCREEN_PERCENTAGE = 0.052f
private const val TEXT_PADDING_SCREEN_PERCENTAGE = 0.0416f
private val indicatorPadding = 8.dp
private val iconSize = 48.dp
private val progressBarStrokeWidth = 4.dp

/**
* A screen to request the user to check their paired phone to proceed.
*
* <img src="https://media.githubusercontent.com/media/google/horologist/main/docs/auth-composables/check_your_phone_screen.png" height="120" width="120"/>
*/
@Composable
public fun CheckYourPhoneScreen(
modifier: Modifier = Modifier,
) {
private fun ProgressCircle(modifier: Modifier) {
Box(
modifier = modifier.fillMaxSize(),
modifier = modifier
.size(iconSize)
.clip(CircleShape),
) {
Text(
text = stringResource(id = R.string.horologist_check_your_phone_title),
modifier = Modifier
.fillMaxWidth()
.align(Alignment.Center),
textAlign = TextAlign.Center,
CircularProgressIndicator(
modifier = Modifier.size(iconSize - progressBarStrokeWidth + indicatorPadding),
strokeWidth = progressBarStrokeWidth,
)

Box(
modifier = modifier
.padding(bottom = 20.dp)
.align(Alignment.BottomCenter)
.size(iconSize)
Icon(
imageVector = Icons.Default.SecurityUpdateGood,
contentDescription = DECORATIVE_ELEMENT_CONTENT_DESCRIPTION,
modifier = Modifier
.align(Alignment.Center)
.size(iconSize - indicatorPadding - 8.dp)
.clip(CircleShape),
) {
CircularProgressIndicator(
modifier = modifier
.size(iconSize - progressBarStrokeWidth + indicatorPadding),
strokeWidth = progressBarStrokeWidth,
)
Icon(
imageVector = Icons.Default.SecurityUpdateGood,
contentDescription = DECORATIVE_ELEMENT_CONTENT_DESCRIPTION,
modifier = Modifier
.align(Alignment.Center)
.size(iconSize - indicatorPadding - 8.dp)
.clip(CircleShape),
)
}
)
}
}

Expand All @@ -97,53 +80,61 @@ public fun CheckYourPhoneScreen(
@Composable
public fun CheckYourPhoneScreen(
modifier: Modifier = Modifier,
message: String,
message: String? = null,
) {
val configuration = LocalConfiguration.current

val isLarge = configuration.isLargeScreen

val topPadding = (configuration.screenHeightDp * TOP_PADDING_SCREEN_PERCENTAGE).dp
val bottomPadding = (configuration.screenHeightDp * BOTTOM_PADDING_SCREEN_PERCENTAGE).dp
val sidePadding = (configuration.screenHeightDp * SIDE_PADDING_SCREEN_PERCENTAGE).dp
val textPadding =
if (isLarge) (configuration.screenHeightDp * TEXT_PADDING_SCREEN_PERCENTAGE).dp else 0.dp

Column(
modifier = modifier
.fillMaxSize()
.padding(top = topPadding),
.padding(
top = topPadding,
bottom = bottomPadding,
start = sidePadding,
end = sidePadding,
),
) {
Text(
text = stringResource(id = R.string.horologist_check_your_phone_title),
Column(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.CenterHorizontally),
textAlign = TextAlign.Center,
)

Text(
text = message,
modifier = Modifier
.padding(top = 20.dp)
.fillMaxWidth()
.align(Alignment.CenterHorizontally),
textAlign = TextAlign.Center,
)

Box(
modifier = modifier
.padding(vertical = 20.dp)
.fillMaxWidth()
.size(iconSize)
.clip(CircleShape),
contentAlignment = Alignment.Center,
.weight(1f)
.padding(horizontal = textPadding),
verticalArrangement = Arrangement.Center,
) {
CircularProgressIndicator(
modifier = modifier
.size(iconSize - progressBarStrokeWidth + indicatorPadding),
strokeWidth = progressBarStrokeWidth,
)
Icon(
imageVector = Icons.Default.SecurityUpdateGood,
contentDescription = DECORATIVE_ELEMENT_CONTENT_DESCRIPTION,
Text(
text = stringResource(id = R.string.horologist_check_your_phone_title),
modifier = Modifier
.size(iconSize - indicatorPadding - 8.dp)
.clip(CircleShape),
.fillMaxWidth()
.align(Alignment.CenterHorizontally),
textAlign = TextAlign.Center,
)

if (message != null) {
Text(
text = message,
modifier = Modifier
.padding(top = 20.dp)
.fillMaxWidth()
.align(Alignment.CenterHorizontally),
textAlign = TextAlign.Center,
)
}
}

ProgressCircle(
Modifier
.align(Alignment.CenterHorizontally),
)
}
}

/** Whether the device is considered large screen for layout adjustment purposes. */
internal val Configuration.isLargeScreen: Boolean get() = screenHeightDp > 224
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
package com.google.android.horologist.auth.composables.screens

import com.google.android.horologist.screenshots.ScreenshotBaseTest
import com.google.android.horologist.screenshots.ScreenshotTestRule
import org.junit.Test

class CheckYourPhoneScreenTest : ScreenshotBaseTest() {
class CheckYourPhoneScreenTest : ScreenshotBaseTest(
params = ScreenshotTestRule.screenshotTestRuleParams {
screenTimeText = {}
},
) {

@Test
fun checkYourPhoneScreen() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import org.junit.Test
class VerticalPagerScreenScreenshotTest : ScreenshotBaseTest(
params = ScreenshotTestRule.screenshotTestRuleParams {
screenTimeText = {}
record = ScreenshotTestRule.RecordMode.Record
},
) {

Expand Down
3 changes: 2 additions & 1 deletion roboscreenshots/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ package com.google.android.horologist.screenshots.rng {
ctor public WearDeviceScreenshotTest(com.google.android.horologist.screenshots.rng.WearDevice device);
method @org.robolectric.ParameterizedRobolectricTestRunner.Parameters public static final java.util.List<com.google.android.horologist.screenshots.rng.WearDevice> devices();
method public com.google.android.horologist.screenshots.rng.WearDevice getDevice();
method public final void runTest(kotlin.jvm.functions.Function0<kotlin.Unit> content);
property public com.google.android.horologist.screenshots.rng.WearDevice device;
property public float tolerance;
field public static final com.google.android.horologist.screenshots.rng.WearDeviceScreenshotTest.Companion Companion;
Expand All @@ -142,7 +143,7 @@ package com.google.android.horologist.screenshots.rng {
method @org.junit.Rule public final androidx.compose.ui.test.junit4.ComposeContentTestRule getComposeRule();
method public abstract com.google.android.horologist.screenshots.rng.WearDevice getDevice();
method public float getTolerance();
method public void runTest(kotlin.jvm.functions.Function0<kotlin.Unit> content);
method public final void runTest(optional String? suffix, kotlin.jvm.functions.Function0<kotlin.Unit> content);
property @org.junit.Rule public final androidx.compose.ui.test.junit4.ComposeContentTestRule composeRule;
property public abstract com.google.android.horologist.screenshots.rng.WearDevice device;
property public float tolerance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import org.robolectric.ParameterizedRobolectricTestRunner
public abstract class WearDeviceScreenshotTest(override val device: WearDevice) : WearScreenshotTest() {
public override val tolerance: Float = 0.02f

override fun runTest(content: @Composable () -> Unit) {
super.runTest(content)
public fun runTest(content: @Composable () -> Unit) {
runTest(suffix = null, content)
}

public companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class WearScreenshotTest {
// Allow for individual tolerances to be set on each test, should be between 0.0 and 1.0
public open val tolerance: Float = 0.0f

public open fun runTest(content: @Composable () -> Unit) {
public fun runTest(suffix: String? = null, content: @Composable () -> Unit) {
RuntimeEnvironment.setQualifiers("+w${device.dp}dp-h${device.dp}dp")
RuntimeEnvironment.setFontScale(device.fontScale)

Expand All @@ -60,9 +60,7 @@ public abstract class WearScreenshotTest {
}
}

val suffix = ""

captureScreenshot(suffix)
captureScreenshot(suffix.orEmpty())
}

public fun captureScreenshot(suffix: String) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d4694ae

Please sign in to comment.