Skip to content

Commit

Permalink
Extreme font scaling screenshot (#2213)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: yschimke <[email protected]>
  • Loading branch information
yschimke and yschimke authored May 1, 2024
1 parent a37665a commit cb4d8f0
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.horologist.media.ui

import com.google.android.horologist.media.ui.state.PlayerUiState
import com.google.android.horologist.media.ui.state.model.MediaUiModel
import com.google.android.horologist.media.ui.state.model.TrackPositionUiModel
import com.google.android.horologist.media.ui.uamp.UampColors
import com.google.android.horologist.screenshots.rng.WearDevice
import com.google.android.horologist.screenshots.rng.WearDeviceScreenshotTest
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters
import kotlin.time.Duration.Companion.seconds

@RunWith(ParameterizedRobolectricTestRunner::class)
class MediaPlayerFontScaleTest(device: WearDevice) : WearDeviceScreenshotTest(device) {

@Test
fun mediaPlayerLargeRound() {
mediaPlayerScreen()
}

@Test
fun mediaPlayerScreen() {
val playerUiState = PlayerUiState(
playEnabled = true,
pauseEnabled = true,
seekBackEnabled = true,
seekForwardEnabled = true,
seekInCurrentMediaItemEnabled = true,
seekToPreviousEnabled = false,
seekToNextEnabled = true,
shuffleEnabled = false,
shuffleOn = false,
playPauseEnabled = true,
playing = true,
media = MediaUiModel.Ready(
id = "",
title = "Outro - Totally Here and Now (feat. Alan Watts)",
subtitle = "The Kyoto Connection",
),
trackPositionUiModel = TrackPositionUiModel.Actual(
position = 30.seconds,
duration = 225.seconds,
percent = 0.133f,
),
connected = true,
)

runTest {
MediaPlayerTestCase(
colors = UampColors,
playerUiState = playerUiState,
)
}
}

companion object {
@JvmStatic
@Parameters
fun devices() = listOf(

WearDevice(
id = "small_round_small",
modelName = "Generic Small Round",
screenSizePx = 384,
density = 2.0f,
fontScale = 0.94f,
),
WearDevice(
id = "large_round_small",
modelName = "Generic Large Round",
screenSizePx = 454,
density = 2.0f,
fontScale = 0.94f,
),
WearDevice(
id = "small_round_large",
modelName = "Generic Small Round",
screenSizePx = 384,
density = 2.0f,
fontScale = 1.24f,
),
WearDevice(
id = "large_round_large",
modelName = "Generic Large Round",
screenSizePx = 454,
density = 2.0f,
fontScale = 1.24f,
),
WearDevice(
id = "square_large",
modelName = "Generic Large Round",
screenSizePx = 360,
density = 2.0f,
fontScale = 1.24f,
isRound = false,
),
)
}
}
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.
60 changes: 41 additions & 19 deletions roboscreenshots/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,51 @@ package com.google.android.horologist.screenshots.rng {
public interface ScreenshotTest {
}

public enum WearDevice {
method public final float getDensity();
method public final int getDp();
method public final float getFontScale();
method public final String! getId();
method public final String! getModelName();
method public final int getScreenSizePx();
method public static com.google.android.horologist.screenshots.rng.WearDevice valueOf(String value) throws java.lang.IllegalArgumentException, java.lang.NullPointerException;
method public static com.google.android.horologist.screenshots.rng.WearDevice[] values();
public final class WearDevice {
ctor public WearDevice(String id, String modelName, int screenSizePx, float density, optional float fontScale, optional boolean isRound);
method public String component1();
method public String component2();
method public int component3();
method public float component4();
method public float component5();
method public boolean component6();
method public com.google.android.horologist.screenshots.rng.WearDevice copy(String id, String modelName, int screenSizePx, float density, float fontScale, boolean isRound);
method public float getDensity();
method public int getDp();
method public float getFontScale();
method public String getId();
method public String getModelName();
method public int getScreenSizePx();
method public boolean isRound();
property public final float density;
property public final int dp;
property public final float fontScale;
property public final String! id;
property public final String! modelName;
property public final String id;
property public final boolean isRound;
property public final String modelName;
property public final int screenSizePx;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice GenericLargeRound;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice GenericSmallRound;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice GooglePixelWatch;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice GooglePixelWatchLargeFont;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice MobvoiTicWatchPro5;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice SamsungGalaxyWatch5;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice SamsungGalaxyWatch6;
enum_constant public static final com.google.android.horologist.screenshots.rng.WearDevice SamsungGalaxyWatch6SmallFont;
field public static final com.google.android.horologist.screenshots.rng.WearDevice.Companion Companion;
}

public static final class WearDevice.Companion {
method public java.util.List<com.google.android.horologist.screenshots.rng.WearDevice> getEntries();
method public com.google.android.horologist.screenshots.rng.WearDevice getGenericLargeRound();
method public com.google.android.horologist.screenshots.rng.WearDevice getGenericSmallRound();
method public com.google.android.horologist.screenshots.rng.WearDevice getGooglePixelWatch();
method public com.google.android.horologist.screenshots.rng.WearDevice getGooglePixelWatchLargeFont();
method public com.google.android.horologist.screenshots.rng.WearDevice getMobvoiTicWatchPro5();
method public com.google.android.horologist.screenshots.rng.WearDevice getSamsungGalaxyWatch5();
method public com.google.android.horologist.screenshots.rng.WearDevice getSamsungGalaxyWatch6();
method public com.google.android.horologist.screenshots.rng.WearDevice getSamsungGalaxyWatch6SmallFont();
property public final com.google.android.horologist.screenshots.rng.WearDevice GenericLargeRound;
property public final com.google.android.horologist.screenshots.rng.WearDevice GenericSmallRound;
property public final com.google.android.horologist.screenshots.rng.WearDevice GooglePixelWatch;
property public final com.google.android.horologist.screenshots.rng.WearDevice GooglePixelWatchLargeFont;
property public final com.google.android.horologist.screenshots.rng.WearDevice MobvoiTicWatchPro5;
property public final com.google.android.horologist.screenshots.rng.WearDevice SamsungGalaxyWatch5;
property public final com.google.android.horologist.screenshots.rng.WearDevice SamsungGalaxyWatch6;
property public final com.google.android.horologist.screenshots.rng.WearDevice SamsungGalaxyWatch6SmallFont;
property public final java.util.List<com.google.android.horologist.screenshots.rng.WearDevice> entries;
}

@org.junit.runner.RunWith(ParameterizedRobolectricTestRunner::class) public abstract class WearDeviceScreenshotTest extends com.google.android.horologist.screenshots.rng.WearScreenshotTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,72 @@ package com.google.android.horologist.screenshots.rng

import kotlin.math.roundToInt

public enum class WearDevice(
public data class WearDevice(
public val id: String,
public val modelName: String,
public val screenSizePx: Int,
public val density: Float,
public val fontScale: Float = 1f,
public val isRound: Boolean = true,
) {
MobvoiTicWatchPro5(
id = "ticwatch_pro_5",
modelName = "Mobvoi TicWatch Pro 5",
screenSizePx = 466,
density = 2.0f,
),
SamsungGalaxyWatch5(
id = "galaxy_watch_5",
modelName = "Samsung Galaxy Watch 5",
screenSizePx = 396,
density = 2.0f,
),
SamsungGalaxyWatch6(
id = "galaxy_watch_6",
modelName = "Samsung Galaxy Watch 6 Large",
screenSizePx = 480,
density = 2.125f,
),
GooglePixelWatch(
id = "pixel_watch",
modelName = "Google Pixel Watch",
screenSizePx = 384,
density = 2.0f,
),
GenericSmallRound(
id = "small_round",
modelName = "Generic Small Round",
screenSizePx = 384,
density = 2.0f,
),
GenericLargeRound(
id = "large_round",
modelName = "Generic Large Round",
screenSizePx = 454,
density = 2.0f,
),
SamsungGalaxyWatch6SmallFont(
id = "galaxy_watch_6_small_font",
modelName = "Samsung Galaxy Watch 6 Large",
screenSizePx = 480,
density = 2.125f,
fontScale = 0.94f,
),
GooglePixelWatchLargeFont(
id = "pixel_watch_large_font",
modelName = "Google Pixel Watch",
screenSizePx = 384,
density = 2.0f,
fontScale = 1.24f,
),
;
public companion object {
public val MobvoiTicWatchPro5: WearDevice = WearDevice(
id = "ticwatch_pro_5",
modelName = "Mobvoi TicWatch Pro 5",
screenSizePx = 466,
density = 2.0f,
)
public val SamsungGalaxyWatch5: WearDevice = WearDevice(
id = "galaxy_watch_5",
modelName = "Samsung Galaxy Watch 5",
screenSizePx = 396,
density = 2.0f,
)
public val SamsungGalaxyWatch6: WearDevice = WearDevice(
id = "galaxy_watch_6",
modelName = "Samsung Galaxy Watch 6 Large",
screenSizePx = 480,
density = 2.125f,
)
public val GooglePixelWatch: WearDevice = WearDevice(
id = "pixel_watch",
modelName = "Google Pixel Watch",
screenSizePx = 384,
density = 2.0f,
)
public val GenericSmallRound: WearDevice = WearDevice(
id = "small_round",
modelName = "Generic Small Round",
screenSizePx = 384,
density = 2.0f,
)
public val GenericLargeRound: WearDevice = WearDevice(
id = "large_round",
modelName = "Generic Large Round",
screenSizePx = 454,
density = 2.0f,
)
public val SamsungGalaxyWatch6SmallFont: WearDevice = SamsungGalaxyWatch6.copy(
id = "galaxy_watch_6_small_font",
modelName = "Samsung Galaxy Watch 6 Large",
fontScale = 0.94f,
)
public val GooglePixelWatchLargeFont: WearDevice = GooglePixelWatch.copy(
id = "pixel_watch_large_font",
modelName = "Google Pixel Watch",
fontScale = 1.24f,
)
public val entries: List<WearDevice> = listOf(
MobvoiTicWatchPro5,
SamsungGalaxyWatch5,
SamsungGalaxyWatch6,
GooglePixelWatch,
GenericSmallRound,
GenericLargeRound,
SamsungGalaxyWatch6SmallFont,
GooglePixelWatchLargeFont,
)
}

public val dp: Int = (screenSizePx / density).roundToInt()
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public abstract class WearScreenshotTest {
) {
withDrawingEnabled(forceHardware) {
if (applyDeviceConfig && device != null) {
RuntimeEnvironment.setQualifiers("+w${device.dp}dp-h${device.dp}dp")
RuntimeEnvironment.setQualifiers("+w${device.dp}dp-h${device.dp}dp" + (if (device.isRound) "" else "-notround"))
RuntimeEnvironment.setFontScale(device.fontScale)
}

Expand Down

0 comments on commit cb4d8f0

Please sign in to comment.