Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Commit a57e661

Browse files
authored
Merge pull request #471 from tiwiz/ae-focus-test
Updates ActivityEmbedding and add Espresso initial tests
2 parents a14e648 + cdd52d2 commit a57e661

File tree

8 files changed

+92
-25
lines changed

8 files changed

+92
-25
lines changed

CanonicalLayouts/list-detail-activity-embedding/app/build.gradle

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ plugins {
1919
}
2020

2121
android {
22-
compileSdk 32
22+
compileSdk 34
2323

2424
defaultConfig {
2525
applicationId "com.example.activityembedding"
2626
minSdk 31
27-
targetSdk 32
27+
targetSdk 34
2828
versionCode 1
2929
versionName "1.0"
3030

@@ -48,23 +48,30 @@ android {
4848
kotlinOptions {
4949
jvmTarget = '1.8'
5050
}
51+
namespace 'com.example.activityembedding'
5152
}
5253

5354
dependencies {
5455

55-
implementation 'androidx.core:core-ktx:1.7.0'
56-
implementation 'androidx.appcompat:appcompat:1.3.0'
57-
implementation 'com.google.android.material:material:1.4.0'
58-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
59-
implementation "androidx.recyclerview:recyclerview:1.2.1"
56+
implementation 'androidx.core:core-ktx:1.13.1'
57+
implementation 'androidx.appcompat:appcompat:1.7.0'
58+
implementation 'com.google.android.material:material:1.12.0'
59+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
60+
implementation "androidx.recyclerview:recyclerview:1.3.2"
6061
// For control over item selection of both touch and mouse driven selection
6162
implementation "androidx.recyclerview:recyclerview-selection:1.1.0"
6263
implementation "androidx.cardview:cardview:1.0.0"
63-
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
64-
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
65-
implementation("androidx.window:window:1.1.0-alpha03")
66-
implementation("androidx.startup:startup-runtime:1.1.0")
64+
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
65+
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
66+
implementation("androidx.window:window:1.3.0")
67+
implementation("androidx.startup:startup-runtime:1.1.1")
6768
testImplementation 'junit:junit:4.13.2'
68-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
69-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
69+
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
70+
androidTestImplementation("androidx.test:core-ktx:1.6.1")
71+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
72+
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.6.1'
73+
androidTestImplementation 'androidx.test.espresso:espresso-device:1.0.1'
74+
androidTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
75+
androidTestImplementation("androidx.test.ext:truth:1.6.0")
76+
androidTestImplementation("androidx.test:runner:1.6.1")
7077
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.activityembedding
17+
18+
import androidx.test.core.app.launchActivity
19+
import androidx.test.espresso.Espresso.onView
20+
import androidx.test.espresso.action.ViewActions.click
21+
import androidx.test.espresso.assertion.ViewAssertions
22+
import androidx.test.espresso.assertion.ViewAssertions.*
23+
import androidx.test.espresso.contrib.RecyclerViewActions
24+
import androidx.test.espresso.matcher.ViewMatchers
25+
import androidx.test.espresso.matcher.ViewMatchers.*
26+
import androidx.test.ext.junit.rules.activityScenarioRule
27+
import androidx.test.ext.junit.runners.AndroidJUnit4
28+
import org.junit.Rule
29+
import org.junit.Test
30+
import org.junit.runner.RunWith
31+
32+
@RunWith(AndroidJUnit4::class)
33+
class MainActivityTest {
34+
35+
@get:Rule
36+
var activityScenarioRule = activityScenarioRule<MainActivity>()
37+
38+
39+
@Test
40+
fun when_device_opens_activity_embedding_espresso_does_not_crash() {
41+
launchActivity<MainActivity>().use {
42+
onView(withId(R.id.list)).perform(
43+
RecyclerViewActions.actionOnItemAtPosition<CustomAdapter.ViewHolder>(
44+
0,
45+
click()
46+
)
47+
)
48+
49+
onView(withId(R.id.list)).check(matches(isNotFocused()))
50+
}
51+
52+
}
53+
}

CanonicalLayouts/list-detail-activity-embedding/app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
limitations under the License.
1616
-->
1717
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18-
xmlns:tools="http://schemas.android.com/tools"
19-
package="com.example.activityembedding">
18+
xmlns:tools="http://schemas.android.com/tools">
2019

2120
<application
2221
android:allowBackup="true"
@@ -49,6 +48,10 @@
4948
</intent-filter>
5049
</activity>
5150

51+
<property
52+
android:name="android.window.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED"
53+
android:value="true" />
54+
5255
<provider
5356
android:name="androidx.startup.InitializationProvider"
5457
android:authorities="${applicationId}.androidx-startup"

CanonicalLayouts/list-detail-activity-embedding/app/src/main/java/com/example/activityembedding/WindowInitializer.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ package com.example.activityembedding
2020
import android.content.Context
2121
import androidx.startup.Initializer
2222
import androidx.window.core.ExperimentalWindowApi
23+
import androidx.window.embedding.RuleController
2324
import androidx.window.embedding.SplitController
2425

25-
class WindowInitializer : Initializer<SplitController> {
26-
override fun create(context: Context): SplitController {
27-
SplitController.initialize(context, R.xml.split_configuration)
28-
return SplitController.getInstance()
26+
class WindowInitializer : Initializer<RuleController> {
27+
override fun create(context: Context): RuleController {
28+
return RuleController.getInstance(context).apply {
29+
setRules(RuleController.parseRules(context, R.xml.split_configuration))
30+
}
2931
}
3032

3133
override fun dependencies(): List<Class<out Initializer<*>>> {

CanonicalLayouts/list-detail-activity-embedding/app/src/main/res/xml/split_configuration.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- Automatically split the following activity pairs. -->
2121
<SplitPairRule
2222
window:splitRatio="0.3"
23-
window:splitMinWidth="840dp"
23+
window:splitMinWidthDp="600"
2424
window:finishPrimaryWithSecondary="adjacent"
2525
window:finishSecondaryWithPrimary="always">
2626
<SplitPairFilter
@@ -36,7 +36,7 @@
3636
<SplitPlaceholderRule
3737
window:placeholderActivityName=".PlaceholderActivity"
3838
window:splitRatio="0.3"
39-
window:splitMinWidth="840dp">
39+
window:splitMinWidthDp="600">
4040
<ActivityFilter
4141
window:activityName=".MainActivity"/>
4242
</SplitPlaceholderRule>

CanonicalLayouts/list-detail-activity-embedding/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1717
plugins {
18-
id 'com.android.application' version '7.2.2' apply false
19-
id 'com.android.library' version '7.2.2' apply false
18+
id 'com.android.application' version '8.5.0' apply false
19+
id 'com.android.library' version '8.5.0' apply false
2020
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
2121
}
2222

CanonicalLayouts/list-detail-activity-embedding/gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ kotlin.code.style=official
2626
# Enables namespacing of each library's R class so that its R class includes only the
2727
# resources declared in the library itself and none from the library's dependencies,
2828
# thereby reducing the size of the R class for that library
29-
android.nonTransitiveRClass=true
29+
android.nonTransitiveRClass=true
30+
android.defaults.buildfeatures.buildconfig=true
31+
android.nonFinalResIds=false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Mon Sep 12 11:25:57 GST 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)