-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
2,471 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.idea/* | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
All font files are licensed under the SIL OPEN FONT LICENSE license. All other files are licensed under the Apache 2 license. | ||
|
||
|
||
SIL OPEN FONT LICENSE | ||
Version 1.1 - 26 February 2007 | ||
|
||
PREAMBLE | ||
The goals of the Open Font License (OFL) are to stimulate worldwide | ||
development of collaborative font projects, to support the font creation | ||
efforts of academic and linguistic communities, and to provide a free and | ||
open framework in which fonts may be shared and improved in partnership | ||
with others. | ||
|
||
The OFL allows the licensed fonts to be used, studied, modified and | ||
redistributed freely as long as they are not sold by themselves. The | ||
fonts, including any derivative works, can be bundled, embedded, | ||
redistributed and/or sold with any software provided that any reserved | ||
names are not used by derivative works. The fonts and derivatives, | ||
however, cannot be released under any other type of license. The | ||
requirement for fonts to remain under this license does not apply | ||
to any document created using the fonts or their derivatives. | ||
|
||
DEFINITIONS | ||
"Font Software" refers to the set of files released by the Copyright | ||
Holder(s) under this license and clearly marked as such. This may | ||
include source files, build scripts and documentation. | ||
|
||
"Reserved Font Name" refers to any names specified as such after the | ||
copyright statement(s). | ||
|
||
"Original Version" refers to the collection of Font Software components as | ||
distributed by the Copyright Holder(s). | ||
|
||
"Modified Version" refers to any derivative made by adding to, deleting, | ||
or substituting — in part or in whole — any of the components of the | ||
Original Version, by changing formats or by porting the Font Software to a | ||
new environment. | ||
|
||
"Author" refers to any designer, engineer, programmer, technical | ||
writer or other person who contributed to the Font Software. | ||
|
||
PERMISSION & CONDITIONS | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of the Font Software, to use, study, copy, merge, embed, modify, | ||
redistribute, and sell modified and unmodified copies of the Font | ||
Software, subject to the following conditions: | ||
|
||
1) Neither the Font Software nor any of its individual components, | ||
in Original or Modified Versions, may be sold by itself. | ||
|
||
2) Original or Modified Versions of the Font Software may be bundled, | ||
redistributed and/or sold with any software, provided that each copy | ||
contains the above copyright notice and this license. These can be | ||
included either as stand-alone text files, human-readable headers or | ||
in the appropriate machine-readable metadata fields within text or | ||
binary files as long as those fields can be easily viewed by the user. | ||
|
||
3) No Modified Version of the Font Software may use the Reserved Font | ||
Name(s) unless explicit written permission is granted by the corresponding | ||
Copyright Holder. This restriction only applies to the primary font name as | ||
presented to the users. | ||
|
||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
Software shall not be used to promote, endorse or advertise any | ||
Modified Version, except to acknowledge the contribution(s) of the | ||
Copyright Holder(s) and the Author(s) or with their explicit written | ||
permission. | ||
|
||
5) The Font Software, modified or unmodified, in part or in whole, | ||
must be distributed entirely under this license, and must not be | ||
distributed under any other license. The requirement for fonts to | ||
remain under this license does not apply to any document created | ||
using the Font Software. | ||
|
||
TERMINATION | ||
This license becomes null and void if any of the above conditions are | ||
not met. | ||
|
||
DISCLAIMER | ||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM | ||
OTHER DEALINGS IN THE FONT SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Testing in Jetpack Compose Codelab | ||
|
||
This folder contains the source code for the | ||
[Testing in Jetpack Compose Codelab ](https://developer.android.com/codelabs/jetpack-compose-testing) | ||
codelab. | ||
|
||
## License | ||
``` | ||
Copyright 2021 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. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright 2021 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. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 33 | ||
|
||
defaultConfig { | ||
applicationId "com.example.compose.rally" | ||
minSdkVersion 21 | ||
targetSdkVersion 33 | ||
versionCode 1 | ||
versionName '1.0' | ||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' | ||
|
||
vectorDrawables.useSupportLibrary = true | ||
} | ||
|
||
signingConfigs { | ||
// We use a bundled debug keystore, to allow debug builds from CI to be upgradable | ||
debug { | ||
storeFile rootProject.file('debug.keystore') | ||
storePassword 'android' | ||
keyAlias 'androiddebugkey' | ||
keyPassword 'android' | ||
} | ||
} | ||
|
||
buildTypes { | ||
debug { | ||
signingConfig signingConfigs.debug | ||
} | ||
|
||
release { | ||
minifyEnabled true | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
|
||
buildFeatures { | ||
compose true | ||
|
||
// Disable unused AGP features | ||
buildConfig false | ||
aidl false | ||
renderScript false | ||
resValues false | ||
shaders false | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion "1.3.2" | ||
} | ||
|
||
packagingOptions { | ||
exclude "META-INF/licenses/**" | ||
exclude "META-INF/AL2.0" | ||
exclude "META-INF/LGPL2.1" | ||
} | ||
} | ||
|
||
dependencies { | ||
def composeBom = platform('androidx.compose:compose-bom:2023.01.00') | ||
implementation(composeBom) | ||
androidTestImplementation(composeBom) | ||
|
||
implementation "androidx.appcompat:appcompat:1.6.0" | ||
implementation "androidx.core:core-ktx:1.9.0" | ||
implementation "com.google.android.material:material:1.7.0" | ||
implementation "androidx.fragment:fragment-ktx:1.5.5" | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20" | ||
|
||
// Compose | ||
implementation "androidx.compose.runtime:runtime" | ||
implementation "androidx.compose.ui:ui" | ||
implementation "androidx.compose.foundation:foundation" | ||
implementation "androidx.compose.foundation:foundation-layout" | ||
implementation "androidx.compose.material:material" | ||
implementation "androidx.compose.material:material" | ||
implementation "androidx.compose.runtime:runtime-livedata" | ||
implementation "androidx.compose.ui:ui-tooling-preview" | ||
implementation "androidx.compose.material:material-icons-extended" | ||
implementation "androidx.activity:activity-compose:1.6.1" | ||
debugImplementation "androidx.compose.ui:ui-tooling" | ||
|
||
// Testing dependencies | ||
androidTestImplementation "androidx.arch.core:core-testing:2.1.0" | ||
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.5.1" | ||
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1" | ||
|
||
// Compose testing dependencies | ||
androidTestImplementation "androidx.compose.ui:ui-test" | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4" | ||
debugImplementation "androidx.compose.ui:ui-test-manifest" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
-renamesourcefileattribute SourceFile | ||
|
||
# Repackage classes into the top-level. | ||
-repackageclasses |
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.
104 changes: 104 additions & 0 deletions
104
TestingCodelab/app/src/androidTest/java/com/example/compose/rally/AnimatingCircleTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2021 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.example.compose.rally | ||
|
||
import android.os.Build | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.MainTestClock | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onRoot | ||
import androidx.compose.ui.unit.dp | ||
import androidx.test.filters.SdkSuppress | ||
import com.example.compose.rally.ui.components.AnimatedCircle | ||
import com.example.compose.rally.ui.theme.RallyTheme | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
/** | ||
* Test to showcase [MainTestClock] present in [ComposeTestRule]. It allows for animation | ||
* testing at specific points in time. | ||
* | ||
* For assertions, a simple screenshot testing framework is used. It requires SDK 26+ and to | ||
* be run on a device with 420dpi, as that the density used to generate the golden images | ||
* present in androidTest/assets. It runs bitmap comparisons on device. | ||
* | ||
* Note that different systems can produce slightly different screenshots making the test fail. | ||
*/ | ||
@ExperimentalTestApi | ||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O) | ||
class AnimatingCircleTests { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun circleAnimation_idle_screenshot() { | ||
composeTestRule.mainClock.autoAdvance = true | ||
showAnimatedCircle() | ||
assertScreenshotMatchesGolden("circle_done", composeTestRule.onRoot()) | ||
} | ||
|
||
@Test | ||
fun circleAnimation_initial_screenshot() { | ||
compareTimeScreenshot(0, "circle_initial") | ||
} | ||
|
||
@Test | ||
fun circleAnimation_beforeDelay_screenshot() { | ||
compareTimeScreenshot(499, "circle_initial") | ||
} | ||
|
||
@Test | ||
fun circleAnimation_midAnimation_screenshot() { | ||
compareTimeScreenshot(600, "circle_100") | ||
} | ||
|
||
@Test | ||
fun circleAnimation_animationDone_screenshot() { | ||
compareTimeScreenshot(1500, "circle_done") | ||
} | ||
|
||
private fun compareTimeScreenshot(timeMs: Long, goldenName: String) { | ||
// Start with a paused clock | ||
composeTestRule.mainClock.autoAdvance = false | ||
|
||
// Start the unit under test | ||
showAnimatedCircle() | ||
|
||
// Advance clock (keeping it paused) | ||
composeTestRule.mainClock.advanceTimeBy(timeMs) | ||
|
||
// Take screenshot and compare with golden image in androidTest/assets | ||
assertScreenshotMatchesGolden(goldenName, composeTestRule.onRoot()) | ||
} | ||
|
||
private fun showAnimatedCircle() { | ||
composeTestRule.setContent { | ||
RallyTheme { | ||
AnimatedCircle( | ||
modifier = Modifier.background(Color.White).size(320.dp), | ||
proportions = listOf(0.25f, 0.5f, 0.25f), | ||
colors = listOf(Color.Red, Color.DarkGray, Color.Black) | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.