Skip to content

Commit

Permalink
Merge pull request #471 from tiwiz/ae-focus-test
Browse files Browse the repository at this point in the history
Updates ActivityEmbedding and add Espresso initial tests
  • Loading branch information
tiwiz authored Jul 18, 2024
2 parents a14e648 + cdd52d2 commit a57e661
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 25 deletions.
33 changes: 20 additions & 13 deletions CanonicalLayouts/list-detail-activity-embedding/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ plugins {
}

android {
compileSdk 32
compileSdk 34

defaultConfig {
applicationId "com.example.activityembedding"
minSdk 31
targetSdk 32
targetSdk 34
versionCode 1
versionName "1.0"

Expand All @@ -48,23 +48,30 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.example.activityembedding'
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.recyclerview:recyclerview:1.3.2"
// For control over item selection of both touch and mouse driven selection
implementation "androidx.recyclerview:recyclerview-selection:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
implementation("androidx.window:window:1.1.0-alpha03")
implementation("androidx.startup:startup-runtime:1.1.0")
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
implementation("androidx.window:window:1.3.0")
implementation("androidx.startup:startup-runtime:1.1.1")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation("androidx.test:core-ktx:1.6.1")
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.6.1'
androidTestImplementation 'androidx.test.espresso:espresso-device:1.0.1'
androidTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
androidTestImplementation("androidx.test.ext:truth:1.6.0")
androidTestImplementation("androidx.test:runner:1.6.1")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.example.activityembedding

import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MainActivityTest {

@get:Rule
var activityScenarioRule = activityScenarioRule<MainActivity>()


@Test
fun when_device_opens_activity_embedding_espresso_does_not_crash() {
launchActivity<MainActivity>().use {
onView(withId(R.id.list)).perform(
RecyclerViewActions.actionOnItemAtPosition<CustomAdapter.ViewHolder>(
0,
click()
)
)

onView(withId(R.id.list)).check(matches(isNotFocused()))
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.activityembedding">
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
Expand Down Expand Up @@ -49,6 +48,10 @@
</intent-filter>
</activity>

<property
android:name="android.window.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED"
android:value="true" />

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ package com.example.activityembedding
import android.content.Context
import androidx.startup.Initializer
import androidx.window.core.ExperimentalWindowApi
import androidx.window.embedding.RuleController
import androidx.window.embedding.SplitController

class WindowInitializer : Initializer<SplitController> {
override fun create(context: Context): SplitController {
SplitController.initialize(context, R.xml.split_configuration)
return SplitController.getInstance()
class WindowInitializer : Initializer<RuleController> {
override fun create(context: Context): RuleController {
return RuleController.getInstance(context).apply {
setRules(RuleController.parseRules(context, R.xml.split_configuration))
}
}

override fun dependencies(): List<Class<out Initializer<*>>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- Automatically split the following activity pairs. -->
<SplitPairRule
window:splitRatio="0.3"
window:splitMinWidth="840dp"
window:splitMinWidthDp="600"
window:finishPrimaryWithSecondary="adjacent"
window:finishSecondaryWithPrimary="always">
<SplitPairFilter
Expand All @@ -36,7 +36,7 @@
<SplitPlaceholderRule
window:placeholderActivityName=".PlaceholderActivity"
window:splitRatio="0.3"
window:splitMinWidth="840dp">
window:splitMinWidthDp="600">
<ActivityFilter
window:activityName=".MainActivity"/>
</SplitPlaceholderRule>
Expand Down
4 changes: 2 additions & 2 deletions CanonicalLayouts/list-detail-activity-embedding/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'com.android.application' version '8.5.0' apply false
id 'com.android.library' version '8.5.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Sep 12 11:25:57 GST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit a57e661

Please sign in to comment.