Skip to content

Commit

Permalink
Added integration for DragAndDrop sample with new screen manager SDK (#…
Browse files Browse the repository at this point in the history
…21)

Added integration for DragAndDrop sample with new screen manager SDK
  • Loading branch information
ancirja-m authored Dec 9, 2020
1 parent 5f1b29a commit 38c261e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 15 deletions.
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

0 comments on commit 38c261e

Please sign in to comment.