Skip to content

Commit

Permalink
Merge pull request #24 from microsoft/integration-with-new-sdk
Browse files Browse the repository at this point in the history
Integration with the new dual screen libraries 1.0.0-beta1
  • Loading branch information
ancirja-m authored Dec 9, 2020
2 parents eb1c348 + 0638b72 commit d47d60c
Show file tree
Hide file tree
Showing 75 changed files with 1,123 additions and 738 deletions.
3 changes: 2 additions & 1 deletion CompanionPane/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ dependencies {
implementation androidxDependencies.ktxCore
implementation androidxDependencies.ktxFragment

implementation microsoftDependencies.dualScreenLayout
implementation microsoftDependencies.screenManager
implementation microsoftDependencies.layouts

testImplementation testDependencies.junit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LayoutOrientationTest {
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

@get:Rule
val activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
val activityRule = ActivityTestRule(MainActivity::class.java)

@After
fun resetOrientation() {
Expand All @@ -37,61 +37,45 @@ class LayoutOrientationTest {

@Test
fun shouldFindLayout_whenInSinglePortrait() {
onView(withId(R.id.single_screen_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.single_screen_layout_port)).check(matches(isDisplayed()))
}

@Test
fun shouldFindLayout_whenInSingleLandscape() {
rotateDevice()

onView(withId(R.id.single_screen_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.single_screen_layout_land)).check(matches(isDisplayed()))
}

@Test
fun shouldFindLayouts_whenInDoublePortrait() {
spanApplication()

onView(withId(R.id.dual_screen_start_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.picture_dual_layout)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.dual_screen_layout_land_start)).check(matches(isDisplayed()))

onView(withId(R.id.dual_screen_end_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.tools_dual_layout_land)).check(matches(isDisplayed()))
onView(withId(R.id.second_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.dual_screen_layout_land_end)).check(matches(isDisplayed()))
}

@Test
fun shouldFindLayouts_whenInDoubleLandscape() {
spanApplication()
rotateDevice()

onView(withId(R.id.dual_screen_start_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.picture_dual_layout)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.dual_screen_layout_port_start)).check(matches(isDisplayed()))

onView(withId(R.id.dual_screen_end_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.tools_dual_layout_port)).check(matches(isDisplayed()))
}

@Test
fun shouldFindLayouts_whenSpanningInDoubleLandscape() {
rotateDevice()
spanLandscapeApplication()

onView(withId(R.id.dual_screen_start_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.picture_dual_layout)).check(matches(isDisplayed()))

onView(withId(R.id.dual_screen_end_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.tools_dual_layout_port)).check(matches(isDisplayed()))
onView(withId(R.id.second_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.dual_screen_layout_port_end)).check(matches(isDisplayed()))
}

private fun spanApplication() {
device.swipe(675, 1780, 1350, 900, 400)
}

private fun spanLandscapeApplication() {
device.swipe(1780, 2100, 1350, 1500, 400)
}

private fun rotateDevice() {
device.setOrientationLeft()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_screen_layout_port"
android:id="@+id/dual_screen_layout_land_end"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_screen_layout_port"
android:id="@+id/dual_screen_layout_land_start"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_screen_layout_port"
android:id="@+id/dual_screen_layout_port_end"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/large_padding"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_screen_layout_port"
android:id="@+id/dual_screen_layout_port_start"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
Expand Down
2 changes: 1 addition & 1 deletion CompanionPane/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
~
-->

<com.microsoft.device.dualscreen.layout.SurfaceDuoLayout
<com.microsoft.device.dualscreen.layouts.SurfaceDuoLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
Expand Down
6 changes: 4 additions & 2 deletions DragAndDrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ android {
}

dependencies {
implementation microsoftDependencies.screenManager
implementation microsoftDependencies.layouts
implementation microsoftDependencies.fragmentsHandler

implementation kotlinDependencies.kotlinStdlib
implementation androidxDependencies.appCompat
implementation androidxDependencies.constraintLayout
implementation androidxDependencies.ktxCore
implementation androidxDependencies.ktxFragment
implementation googleDependencies.material

implementation microsoftDependencies.dualScreenLayout

testImplementation testDependencies.junit

androidTestImplementation instrumentationTestDependencies.junit
Expand Down
4 changes: 2 additions & 2 deletions DragAndDrop/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) Microsoft Corporation. All rights reserved.
~ Licensed under the MIT License.
~
Expand All @@ -9,6 +8,7 @@
package="com.microsoft.device.display.samples.draganddrop">

<application
android:name=".DragAndDropApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*
*/

package com.microsoft.device.display.samples.draganddrop

import android.app.Application
import com.microsoft.device.dualscreen.ScreenManagerProvider
import com.microsoft.device.dualscreen.fragmentshandler.FragmentManagerStateHandler

class DragAndDropApplication : Application() {
override fun onCreate() {
super.onCreate()
ScreenManagerProvider.init(this)
FragmentManagerStateHandler.init(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,83 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.microsoft.device.display.samples.draganddrop.fragment.DragSourceFragment
import com.microsoft.device.display.samples.draganddrop.fragment.DropTargetFragment
import com.microsoft.device.dualscreen.layout.ScreenHelper
import com.microsoft.device.dualscreen.ScreenInfo
import com.microsoft.device.dualscreen.ScreenInfoListener
import com.microsoft.device.dualscreen.ScreenManagerProvider
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
class MainActivity : AppCompatActivity(), ScreenInfoListener {

companion object {
private const val FRAGMENT_SINGLE_SCREEN_DRAG_SOURCE = "FragmentSingleScreenDragSource"
private const val FRAGMENT_SINGLE_SCREEN_DROP_TARGET = "FragmentSingleScreenDropTarget"
private const val FRAGMENT_DUAL_SCREEN_DRAG_SOURCE = "FragmentDualScreenDragSource"
private const val FRAGMENT_DUAL_SCREEN_DROP_TARGET = "FragmentDualScreenDropTarget"
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

reset_button.setOnClickListener { recreate() }
}

override fun onScreenInfoChanged(screenInfo: ScreenInfo) {
setupLayout(screenInfo)
}

if (!ScreenHelper.isDualMode(this)) {
override fun onResume() {
super.onResume()
ScreenManagerProvider.getScreenManager().addScreenInfoListener(this)
}

override fun onPause() {
super.onPause()
ScreenManagerProvider.getScreenManager().removeScreenInfoListener(this)
}

private fun setupLayout(screenInfo: ScreenInfo) {
if (!screenInfo.isDualMode()) {
setupLayoutForSingleScreen()
} else {
setupLayoutForDualScreen()
}
}

private fun setupLayoutForSingleScreen() {
if (supportFragmentManager.findFragmentByTag(FRAGMENT_SINGLE_SCREEN_DRAG_SOURCE) == null) {
supportFragmentManager.beginTransaction()
.replace(
R.id.drag_source_container,
DragSourceFragment.newInstance()
DragSourceFragment.newInstance(),
FRAGMENT_SINGLE_SCREEN_DRAG_SOURCE
).commit()
}
if (supportFragmentManager.findFragmentByTag(FRAGMENT_SINGLE_SCREEN_DROP_TARGET) == null) {
supportFragmentManager.beginTransaction()
.replace(
R.id.drop_target_container,
DropTargetFragment.newInstance()
DropTargetFragment.newInstance(),
FRAGMENT_SINGLE_SCREEN_DROP_TARGET
).commit()
} else {
}
}

private fun setupLayoutForDualScreen() {
if (supportFragmentManager.findFragmentByTag(FRAGMENT_DUAL_SCREEN_DRAG_SOURCE) == null) {
supportFragmentManager.beginTransaction()
.replace(
R.id.dual_screen_start_container_id,
DragSourceFragment.newInstance()
R.id.first_container_id,
DragSourceFragment.newInstance(),
FRAGMENT_DUAL_SCREEN_DRAG_SOURCE
).commit()
}
if (supportFragmentManager.findFragmentByTag(FRAGMENT_DUAL_SCREEN_DROP_TARGET) == null) {
supportFragmentManager.beginTransaction()
.replace(
R.id.dual_screen_end_container_id,
DropTargetFragment.newInstance()
R.id.second_container_id,
DropTargetFragment.newInstance(),
FRAGMENT_DUAL_SCREEN_DROP_TARGET
).commit()
}
}
Expand Down
2 changes: 1 addition & 1 deletion DragAndDrop/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.microsoft.device.dualscreen.layout.SurfaceDuoLayout
<com.microsoft.device.dualscreen.layouts.SurfaceDuoLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:single_screen_layout_id="@layout/single_screen"
Expand Down
4 changes: 3 additions & 1 deletion DualView/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ dependencies {
implementation androidxDependencies.ktxCore
implementation androidxDependencies.ktxFragment

implementation microsoftDependencies.dualScreenLayout
implementation microsoftDependencies.screenManager
implementation microsoftDependencies.layouts
implementation microsoftDependencies.fragmentsHandler

testImplementation testDependencies.junit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class LayoutModeTest {
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

@get:Rule
val activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
val activityRule = ActivityTestRule(MainActivity::class.java)

@Test
fun openMapFromList_whenIsSingleScreen() {
onView(withId(R.id.single_screen_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.list_items)).check(matches(isDisplayed()))

onView(withId(R.id.list_items)).perform(
Expand All @@ -46,16 +46,16 @@ class LayoutModeTest {
fun displayListAndDetailsFromList_whenIsDualScreen() {
spanApplication()

onView(withId(R.id.dual_screen_start_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.dual_screen_end_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.second_container_id)).check(matches(isDisplayed()))

onView(withId(R.id.list_items)).check(matches(isDisplayed()))
onView(withId(R.id.img_view)).check(matches(isDisplayed()))
}

@Test
fun displayListAndDetailsFromMap_whenIsDualScreen() {
onView(withId(R.id.single_screen_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.list_items)).check(matches(isDisplayed()))

onView(withId(R.id.list_items)).perform(
Expand All @@ -64,8 +64,8 @@ class LayoutModeTest {

spanApplication()

onView(withId(R.id.dual_screen_start_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.dual_screen_end_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.first_container_id)).check(matches(isDisplayed()))
onView(withId(R.id.second_container_id)).check(matches(isDisplayed()))

onView(withId(R.id.list_items)).check(matches(isDisplayed()))
onView(withId(R.id.img_view)).check(matches(isDisplayed()))
Expand Down
Loading

0 comments on commit d47d60c

Please sign in to comment.