-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added integration for Photo Editor app with new screen manager SDK (#48)
Added integration for Photo Editor app with new screen manager SDK
- Loading branch information
Showing
37 changed files
with
436 additions
and
206 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
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
55 changes: 55 additions & 0 deletions
55
...est/java/com/microsoft/device/display/samples/photoeditor/utils/ScreenInfoListenerImpl.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,55 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
package com.microsoft.device.display.samples.photoeditor.utils | ||
|
||
import com.microsoft.device.dualscreen.ScreenInfo | ||
import com.microsoft.device.dualscreen.ScreenInfoListener | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* Simple implementation for [ScreenInfoListener] that saves internally the last screen info data. | ||
*/ | ||
class ScreenInfoListenerImpl : ScreenInfoListener { | ||
private var _screenInfo: ScreenInfo? = null | ||
val screenInfo: ScreenInfo? | ||
get() = _screenInfo | ||
private var screenInfoLatch: CountDownLatch? = null | ||
|
||
override fun onScreenInfoChanged(screenInfo: ScreenInfo) { | ||
_screenInfo = screenInfo | ||
screenInfoLatch?.countDown() | ||
} | ||
|
||
/** | ||
* Resets the last screen info to [null] | ||
*/ | ||
fun resetScreenInfo() { | ||
_screenInfo = null | ||
} | ||
|
||
/** | ||
* Resets screen info counter when waiting for a screen changes to happen before calling | ||
* [waitForScreenInfoChanges]. | ||
*/ | ||
fun resetScreenInfoCounter() { | ||
screenInfoLatch = CountDownLatch(1) | ||
} | ||
|
||
/** | ||
* Blocks and waits for the next screen info changes to happen. | ||
* @return {@code true} if the screen info changed before the timeout count reached zero and | ||
* {@code false} if the waiting time elapsed before the changes happened. | ||
*/ | ||
fun waitForScreenInfoChanges(): Boolean { | ||
return try { | ||
val result = screenInfoLatch?.await(10, TimeUnit.SECONDS) ?: false | ||
result | ||
} catch (e: InterruptedException) { | ||
false | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
.../app/src/main/java/com/microsoft/device/display/samples/photoeditor/LiveDataExtensions.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,21 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
package com.microsoft.device.display.samples.photoeditor | ||
|
||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.Observer | ||
|
||
fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner, observer: Observer<T>) { | ||
class RemovableObserver : Observer<T> { | ||
override fun onChanged(t: T?) { | ||
observer.onChanged(t) | ||
removeObserver(this) | ||
} | ||
} | ||
|
||
observe(lifecycleOwner, RemovableObserver()) | ||
} |
Oops, something went wrong.