Introducing Windowstate as a new SDK (#9)
* Create WindowState project * Bring in the implementation * Update dependencies * Update publishing url for WindowState and TwoPaneLayout * Add sample to showcase WindowState * Code clean up * Update WindowSizeClass entry * Update foldSize and paneWidth in Dp value * Update README * Remove unnecessary test case * Update the pipeline to include WindowState * Add missing files * Delete local.properties * Address the comment * Add publish yml files * Fix the wrong name
|
@ -21,7 +21,7 @@ jobs:
|
|||
|
||||
strategy:
|
||||
matrix:
|
||||
projects: [ TwoPaneLayout ]
|
||||
projects: [ TwoPaneLayout, WindowState ]
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
# This workflow will build a Java project with Gradle
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||
|
||||
name: publish-WindowState-ado
|
||||
# This workflow builds and publishes in ADO the WindowState Compose artifact.
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'windowstate*'
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
name:
|
||||
description: 'Triggers publication to ADO - WindowState Compose'
|
||||
home:
|
||||
description: 'location'
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
publish-WindowState-ADO:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./WindowState
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
|
||||
- name: Cache Gradle packages
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
|
||||
restore-keys: ${{ runner.os }}-gradle
|
||||
|
||||
# Base64 decodes and pipes the GPG key content into the secret file
|
||||
- name: Prepare environment
|
||||
env:
|
||||
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
|
||||
SIGNING_SECRET_FILE: ${{ secrets.SIGNING_SECRET_FILE }}
|
||||
run: |
|
||||
git fetch --unshallow
|
||||
sudo bash -c "echo '$SIGNING_SECRET_KEY' | base64 -d > '$SIGNING_SECRET_FILE'"
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
|
||||
- name: clean
|
||||
run: ./gradlew :library:clean --info
|
||||
|
||||
# Builds the release artifacts of the library
|
||||
- name: Release build
|
||||
run: ./gradlew :library:assembleRelease
|
||||
|
||||
# Generates other artifacts
|
||||
- name: Source jar
|
||||
run: ./gradlew :library:androidSourcesJar
|
||||
|
||||
# Generates docs artifact
|
||||
- name: Docs jar
|
||||
run: ./gradlew :library:dokkaHtmlJar
|
||||
|
||||
# Runs upload to ADO
|
||||
- name: Publish to ADO
|
||||
run: ./gradlew :library:publishSurfaceDuoComposePublicationToADORepository --max-workers 1
|
||||
env:
|
||||
ADO_URL: ${{ secrets.ADO_URL }}
|
||||
ADO_USER: ${{ secrets.ADO_USER }}
|
||||
ADO_PASSWD: ${{ secrets.ADO_PASSWD }}
|
||||
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
|
||||
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
|
||||
SIGNING_SECRET_FILE: ${{ secrets.SIGNING_SECRET_FILE }}
|
|
@ -0,0 +1,77 @@
|
|||
# This workflow will build a Java project with Gradle
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||
|
||||
name: publish-WindowState-mavencentral
|
||||
# This workflow builds and publishes in Maven Central the WindowState Compose artifact.
|
||||
# The final publishing step has to be done manually in Sonatype site.
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'windowstate*'
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
name:
|
||||
description: 'Triggers publication to MavenCentral - WindowState Compose'
|
||||
home:
|
||||
description: 'location'
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
publish-WindowState-MavenCentral:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./WindowState
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
|
||||
- name: Cache Gradle packages
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
|
||||
restore-keys: ${{ runner.os }}-gradle
|
||||
|
||||
# Base64 decodes and pipes the GPG key content into the secret file
|
||||
- name: Prepare environment
|
||||
env:
|
||||
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
|
||||
SIGNING_SECRET_FILE: ${{ secrets.SIGNING_SECRET_FILE }}
|
||||
run: |
|
||||
git fetch --unshallow
|
||||
sudo bash -c "echo '$SIGNING_SECRET_KEY' | base64 -d > '$SIGNING_SECRET_FILE'"
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
|
||||
- name: clean
|
||||
run: ./gradlew :library:clean
|
||||
|
||||
# Builds the release artifacts of the library
|
||||
- name: Release build
|
||||
run: ./gradlew :library:assembleRelease
|
||||
|
||||
# Generates other artifacts
|
||||
- name: Source jar
|
||||
run: ./gradlew :library:androidSourcesJar
|
||||
|
||||
# Generates docs artifact
|
||||
- name: Docs jar
|
||||
run: ./gradlew :library:dokkaHtmlJar
|
||||
|
||||
# Runs upload to MavenCentral (final release step will be manually done in Sonatype site)
|
||||
- name: Publish to MavenCentral
|
||||
run: ./gradlew :library:publishSurfaceDuoComposePublicationToMavencentralRepository --max-workers 1
|
||||
env:
|
||||
MAVEN_USER: ${{ secrets.MAVEN_USER }}
|
||||
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
|
||||
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
|
||||
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
|
||||
SIGNING_SECRET_FILE: ${{ secrets.SIGNING_SECRET_FILE }}
|
|
@ -18,7 +18,11 @@ Please check out our page on [Jetpack Compose for Microsoft Surface Duo](https:/
|
|||
|
||||
### [TwoPaneLayout](https://github.com/microsoft/surface-duo-compose-sdk/tree/main/TwoPaneLayout)
|
||||
|
||||
A UI component that help you build two-pane layout for dual-screen, foldable, and large-screen devices.
|
||||
A UI component that helps you build two-pane layout for dual-screen, foldable, and large-screen devices.
|
||||
|
||||
### [WindowState](https://github.com/microsoft/surface-duo-compose-sdk/tree/main/WindowState)
|
||||
|
||||
A utility component that helps you easily get details about the window state of dual-screen, foldable, and large-screen devices.
|
||||
|
||||
## Social links
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ publishing {
|
|||
pom {
|
||||
name = PUBLISH_ARTIFACT_ID
|
||||
description = LIBRARY_DESCRIPTION
|
||||
url = 'https://github.com/microsoft/surface-duo-compose-samples'
|
||||
url = 'https://github.com/microsoft/surface-duo-compose-sdk'
|
||||
licenses {
|
||||
license {
|
||||
name = 'MIT'
|
||||
|
@ -73,9 +73,9 @@ publishing {
|
|||
}
|
||||
// Version control info
|
||||
scm {
|
||||
connection = 'scm:git:github.com/microsoft/surface-duo-compose-samples.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/microsoft/surface-duo-compose-samples.git'
|
||||
url = 'https://github.com/microsoft/surface-duo-compose-samples/tree/main'
|
||||
connection = 'scm:git:github.com/microsoft/surface-duo-compose-sdk.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/microsoft/surface-duo-compose-sdk.git'
|
||||
url = 'https://github.com/microsoft/surface-duo-compose-sdk/tree/main'
|
||||
}
|
||||
// A slightly hacky fix so that your POM will include any transitive dependencies
|
||||
// that your library builds upon
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
### Android template
|
||||
# Built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
release/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea/
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following lines if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
#*.keystore
|
|
@ -0,0 +1,132 @@
|
|||
# WindowState - Surface Duo Compose SDK
|
||||
|
||||
**WindowState** is a component for Jetpack Compose that helps you easily get details about the window state of the dual-screen, foldable and large screen devices, using the Google [Jetpack WindowManager](https://developer.android.com/jetpack/androidx/releases/window) library.
|
||||
|
||||
The component provides the current window information as a Compose state, including folding position, orientation and window size classes. For dual-screen and foldable devices, combining different folding positions and orientations, we introduce four display postures to take advantage of these new form factors: Dual Portrait, Dual Landscape, Single Portrait, Single Landscape.
|
||||
|
||||
![postures](screenshots/postures-overview.png)
|
||||
|
||||
And the window size classes are measured based on Google [Window size classes](https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes#window_size_classes) to help you support different screen sizes of the devices, including large screen and regular single screen devices.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun Activity.rememberWindowState(): WindowState
|
||||
```
|
||||
An interface to provide all the relevant info about the device window.
|
||||
|
||||
```kotlin
|
||||
val foldablePaneWidth: Int
|
||||
```
|
||||
Returns a pixel value of the width of a single pane of the dual-screen or foldable device when the device is in the dual-screen mode. If the device is in the single screen mode, or the device is a regular single screen device, the return value will be 0.
|
||||
|
||||
```kotlin
|
||||
val foldSize: Int
|
||||
```
|
||||
Returns a pixel value of the width of the hinge of dual-screen device or the folding line of foldable device when the device is in the dual-screen mode. If the device is in the single screen mode, or the device is a regular single screen device, the return value will be 0.
|
||||
|
||||
```kotlin
|
||||
val windowMode: WindowMode
|
||||
```
|
||||
Returns the display posture of the window mode: **SINGLE_PORTRAIT**, **SINGLE_LANDSCAPE**, **DUAL_PORTRAIT**, **DUAL_LANDSCAPE**.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun isDualScreen(): Boolean
|
||||
```
|
||||
Check if the device window is in the dual screen mode, we called it **spanned** for the dual-screen device or **unfolded** for the foldable device.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun isDualPortrait(): Boolean
|
||||
```
|
||||
Check if the device window is in the dual portrait posture, with which the hinge or folding line is vertical.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun isDualLandscape(): Boolean
|
||||
```
|
||||
Check if the device window is in the dual portrait posture, with which the hinge or folding line is horizontal.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun isSinglePortrait(): Boolean
|
||||
```
|
||||
Check if the device window is in the single portrait posture, with which the device is in the single screen mode or the device is a single screen device with the portrait orientation.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun isSingleLandscape(): Boolean
|
||||
```
|
||||
Check if the device window is in the single landscape posture, with which the device is in the single screen mode or the device is a single screen device with the landscape orientation.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun widthSizeClass(): WindowSizeClass
|
||||
```
|
||||
Returns the width window size class: **Compact**, **Medium**, **Expanded**, based on the width of the window.
|
||||
|
||||
```kotlin
|
||||
@Composable
|
||||
fun heightSizeClass(): WindowSizeClass
|
||||
```
|
||||
Returns the height window size class: **Compact**, **Medium**, **Expanded**, based on the height of the window.
|
||||
|
||||
## Add to your project
|
||||
|
||||
1. Make sure you have **mavenCentral()** repository in your top level **build.gradle** file:
|
||||
|
||||
```gradle
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Add dependencies to the module-level **build.gradle** file (current version may be different from what's shown here).
|
||||
|
||||
```gradle
|
||||
implementation "com.microsoft.device.dualscreen:windowstate:1.0.0-alpha1"
|
||||
```
|
||||
|
||||
3. Also ensure the compileSdkVersion and targetSdkVersion are set to API 31 or newer in the module-level build.gradle file.
|
||||
|
||||
```gradle
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
|
||||
defaultConfig {
|
||||
targetSdkVersion 31
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
4. Access the info about the window state from **WindowState** to build or adjust your UI. Please refer to the [sample](https://github.com/microsoft/surface-duo-compose-sdk/tree/main/WindowState/sample) for more details.
|
||||
|
||||
## Contributing
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
|
||||
|
||||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
|
||||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
|
||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
*
|
||||
* * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* * Licensed under the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
apply from: 'dependencies.gradle'
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath config.gradlePlugin
|
||||
classpath config.kotlinGradlePlugin
|
||||
classpath dokkaDependencies.dokkaGradlePlugin
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
apply from: "$rootDir/ktlint.gradle"
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
||||
// Used to get the value of a local property or if not found the value that could
|
||||
// be stored in the repo settings as a token.
|
||||
String getPropertyValue(String property) {
|
||||
def localPropertyFound = project.hasProperty(property)
|
||||
def envProperty = System.getenv(property)
|
||||
if (localPropertyFound) {
|
||||
return project.getProperties().get(property)
|
||||
} else if (envProperty != null) {
|
||||
return envProperty
|
||||
} else {
|
||||
return "NO_VALUE"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
ext {
|
||||
|
||||
//---- Important -------------------
|
||||
// We have to update following versionName and versionCode groups in order to
|
||||
// publish correctly a new version of each of our libraries.
|
||||
// e.g. windowstate library, you could have as a current version
|
||||
// 1.0.0-beta1, if you want to publish a new version you will have to increase in one the
|
||||
//windowStateVersionCode and to bump the windowStateVersionName.
|
||||
|
||||
// WindowState library version code:
|
||||
// If you want to publish a new version, bump in one (1) the specific line(s)
|
||||
windowStateVersionCode = 1
|
||||
|
||||
// WindowState library version name:
|
||||
// If you want to publish a new version, bump the specific line
|
||||
windowStateVersionName = '1.0.0-alpha1'
|
||||
|
||||
// ----------------------------------
|
||||
|
||||
gradlePluginVersion = '7.0.3'
|
||||
kotlinVersion = "1.5.31"
|
||||
compileSdkVersion = 31
|
||||
targetSdkVersion = compileSdkVersion
|
||||
minSdkVersion = 23
|
||||
dokkaVersion = "1.6.0"
|
||||
|
||||
config = [
|
||||
gradlePlugin : "com.android.tools.build:gradle:$gradlePluginVersion",
|
||||
kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion",
|
||||
testInstrumentationRunner: "androidx.test.runner.AndroidJUnitRunner"
|
||||
]
|
||||
|
||||
kotlinDependencies = [
|
||||
kotlinStdlib: "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
|
||||
]
|
||||
|
||||
dokkaDependencies = [
|
||||
dokkaGradlePlugin: "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
|
||||
]
|
||||
|
||||
// AndroidX dependencies
|
||||
appCompatVersion = "1.3.0"
|
||||
ktxCoreVersion = "1.5.0"
|
||||
windowVersion = "1.0.0-beta04"
|
||||
|
||||
androidxDependencies = [
|
||||
appCompat : "androidx.appcompat:appcompat:$appCompatVersion",
|
||||
ktxCore : "androidx.core:core-ktx:$ktxCoreVersion",
|
||||
window : "androidx.window:window:$windowVersion"
|
||||
]
|
||||
|
||||
// Compose dependencies
|
||||
composeVersion = "1.0.5"
|
||||
activityComposeVersion = "1.4.0"
|
||||
navigationComposeVersion = "2.4.0-beta02"
|
||||
|
||||
composeDependencies = [
|
||||
composeMaterial : "androidx.compose.material:material:$composeVersion",
|
||||
composeRuntime : "androidx.compose.runtime:runtime-livedata:$composeVersion",
|
||||
composeUI : "androidx.compose.ui:ui:$composeVersion",
|
||||
composeUITooling : "androidx.compose.ui:ui-tooling:$composeVersion",
|
||||
activityCompose : "androidx.activity:activity-compose:$activityComposeVersion",
|
||||
navigationCompose : "androidx.navigation:navigation-compose:$navigationComposeVersion"
|
||||
]
|
||||
|
||||
// Test dependencies
|
||||
androidxTestVersion = "1.4.0"
|
||||
espressoVersion = "3.4.0"
|
||||
junitVersion = "4.12"
|
||||
mockitoVersion = "4.1.0"
|
||||
testDependencies = [
|
||||
androidxTestCore : "androidx.test:core:$androidxTestVersion",
|
||||
androidxTestRules : "androidx.test:rules:$androidxTestVersion",
|
||||
androidxTestRunner : "androidx.test:runner:$androidxTestVersion",
|
||||
composeUITest : "androidx.compose.ui:ui-test:$composeVersion",
|
||||
composeJunit : "androidx.compose.ui:ui-test-junit4:$composeVersion",
|
||||
composeUITestManifest : "androidx.compose.ui:ui-test-manifest:$composeVersion",
|
||||
espressoCore : "androidx.test.espresso:espresso-core:$espressoVersion",
|
||||
androidJunit : "junit:junit:$junitVersion",
|
||||
mockitoCore : "org.mockito:mockito-core:$mockitoVersion"
|
||||
]
|
||||
|
||||
// Google dependencies
|
||||
materialVersion = "1.5.0-alpha01"
|
||||
|
||||
googleDependencies = [
|
||||
material: "com.google.android.material:material:$materialVersion"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app"s APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
|
@ -0,0 +1,6 @@
|
|||
#Wed Jan 05 12:49:04 PST 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
|
@ -0,0 +1,89 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
configurations {
|
||||
ktlint
|
||||
}
|
||||
|
||||
dependencies {
|
||||
ktlint "com.pinterest:ktlint:0.40.0"
|
||||
}
|
||||
|
||||
task ktlint(type: JavaExec, group: "verification") {
|
||||
description = "Check Kotlin code style."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
args "src/**/*.kt"
|
||||
// to generate report in checkstyle format prepend following args:
|
||||
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
|
||||
// see https://github.com/pinterest/ktlint#usage for more
|
||||
}
|
||||
|
||||
task ktlintFormat(type: JavaExec, group: "formatting") {
|
||||
description = "Fix Kotlin code style deviations."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
args "-F", "src/**/*.kt"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
/build
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
//Artifact publication data
|
||||
ext {
|
||||
PUBLISH_GROUP_ID = 'com.microsoft.device.dualscreen'
|
||||
PUBLISH_ARTIFACT_ID = 'windowstate'
|
||||
LIBRARY_DESCRIPTION = 'WindowState Compose library'
|
||||
LIBRARY_VERSION = rootProject.ext.windowStateVersionName
|
||||
}
|
||||
apply from: "${rootProject.projectDir}/publishing.gradle"
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.windowStateVersionCode
|
||||
versionName rootProject.ext.windowStateVersionName
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary true
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion composeVersion
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
exclude 'META-INF/LGPL2.1'
|
||||
exclude 'META-INF/AL2.0'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation kotlinDependencies.kotlinStdlib
|
||||
|
||||
implementation androidxDependencies.ktxCore
|
||||
implementation androidxDependencies.appCompat
|
||||
implementation androidxDependencies.window
|
||||
|
||||
implementation composeDependencies.composeUI
|
||||
implementation composeDependencies.composeRuntime
|
||||
implementation composeDependencies.composeMaterial
|
||||
implementation composeDependencies.composeUITooling
|
||||
implementation composeDependencies.activityCompose
|
||||
|
||||
testImplementation testDependencies.androidJunit
|
||||
testImplementation testDependencies.androidxTestCore
|
||||
testImplementation testDependencies.mockitoCore
|
||||
|
||||
androidTestImplementation testDependencies.androidxTestCore
|
||||
androidTestImplementation testDependencies.androidxTestRules
|
||||
androidTestImplementation testDependencies.androidxTestRunner
|
||||
androidTestImplementation testDependencies.espressoCore
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
import android.graphics.Rect
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class WindowStateTest {
|
||||
private val hasFold = true
|
||||
private val foldBounds = Rect(20, 20, 60, 100)
|
||||
private val foldState = FoldState.HALF_OPENED
|
||||
private val foldSeparates = true
|
||||
private val foldOccludes = true
|
||||
private val windowWidth = 900.dp
|
||||
private val windowHeight = 500.dp
|
||||
|
||||
private val horizontalFold = WindowState(
|
||||
hasFold,
|
||||
true,
|
||||
foldBounds,
|
||||
foldState,
|
||||
foldSeparates,
|
||||
foldOccludes,
|
||||
windowWidth,
|
||||
windowHeight
|
||||
)
|
||||
private val verticalFold = WindowState(
|
||||
hasFold,
|
||||
false,
|
||||
foldBounds,
|
||||
foldState,
|
||||
foldSeparates,
|
||||
foldOccludes
|
||||
)
|
||||
private val noFoldLargeScreen = WindowState(
|
||||
windowWidth = 850.dp,
|
||||
windowHeight = 910.dp
|
||||
)
|
||||
private val noFoldCompact = WindowState()
|
||||
|
||||
@Test
|
||||
fun returns_correct_fold_size() {
|
||||
assertEquals(foldBounds.height(), horizontalFold.foldSize)
|
||||
assertEquals(foldBounds.width(), verticalFold.foldSize)
|
||||
assertEquals(0, noFoldLargeScreen.foldSize)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun portrait_large_screen_returns_dual_land() {
|
||||
assertEquals(WindowMode.DUAL_LANDSCAPE, noFoldLargeScreen.calculateWindowMode(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun landscape_large_screen_returns_dual_port() {
|
||||
assertEquals(WindowMode.DUAL_PORTRAIT, noFoldLargeScreen.calculateWindowMode(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun portrait_compact_returns_single_port() {
|
||||
assertEquals(WindowMode.SINGLE_PORTRAIT, noFoldCompact.calculateWindowMode(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun landscape_compact_returns_single_land() {
|
||||
assertEquals(WindowMode.SINGLE_LANDSCAPE, noFoldCompact.calculateWindowMode(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun vertical_fold_returns_dual_port() {
|
||||
assertEquals(WindowMode.DUAL_PORTRAIT, verticalFold.calculateWindowMode(true))
|
||||
assertEquals(WindowMode.DUAL_PORTRAIT, verticalFold.calculateWindowMode(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun horizontal_fold_returns_dual_land() {
|
||||
assertEquals(WindowMode.DUAL_LANDSCAPE, horizontalFold.calculateWindowMode(true))
|
||||
assertEquals(WindowMode.DUAL_LANDSCAPE, horizontalFold.calculateWindowMode(false))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
~ Licensed under the MIT License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.microsoft.device.dualscreen.windowstate">
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
enum class Dimension { WIDTH, HEIGHT }
|
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
enum class FoldState { FLAT, HALF_OPENED }
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
/**
|
||||
* Class that represents the different modes in which content can be displayed in a window,
|
||||
* depending on window size and orientation
|
||||
*
|
||||
* Window modes:
|
||||
* - single portrait
|
||||
* - single landscape
|
||||
* - dual portrait
|
||||
* - dual landscape
|
||||
*/
|
||||
enum class WindowMode {
|
||||
SINGLE_PORTRAIT,
|
||||
SINGLE_LANDSCAPE,
|
||||
DUAL_PORTRAIT,
|
||||
DUAL_LANDSCAPE;
|
||||
|
||||
val isDualScreen: Boolean get() = this == DUAL_PORTRAIT || this == DUAL_LANDSCAPE
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
enum class WindowSizeClass { COMPACT, MEDIUM, EXPANDED }
|
||||
|
||||
/**
|
||||
* Calculates size class for a given dimension
|
||||
*
|
||||
* @param dimenDp: size of dimension in Dp
|
||||
* @param dimen: which dimension is being measured (width or height)
|
||||
*/
|
||||
fun getWindowSizeClass(dimenDp: Dp, dimen: Dimension = Dimension.WIDTH): WindowSizeClass =
|
||||
when (dimen) {
|
||||
Dimension.WIDTH -> getSizeClass(dimenDp, 600.dp, 840.dp)
|
||||
Dimension.HEIGHT -> getSizeClass(dimenDp, 480.dp, 900.dp)
|
||||
}
|
||||
|
||||
private fun getSizeClass(size: Dp, medium: Dp, expanded: Dp): WindowSizeClass = when {
|
||||
size < 0.dp -> throw IllegalArgumentException("Dp value cannot be negative")
|
||||
size < medium -> WindowSizeClass.COMPACT
|
||||
size < expanded -> WindowSizeClass.MEDIUM
|
||||
else -> WindowSizeClass.EXPANDED
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Rect
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/**
|
||||
* Data class that contains foldable and large screen information extracted from the Jetpack
|
||||
* Window Manager library
|
||||
*
|
||||
* @param hasFold: true if window contains a FoldingFeature,
|
||||
* @param isFoldHorizontal: true if window contains a FoldingFeature with a horizontal orientation
|
||||
* @param foldBounds: Rect object that describes the bound of the FoldingFeature
|
||||
* @param foldState: state of the fold, based on state property of FoldingFeature
|
||||
* @param foldSeparates: based on isSeparating property of FoldingFeature
|
||||
* @param foldOccludes: true if FoldingFeature occlusion type is full
|
||||
* @param windowWidth: Dp value of the window width
|
||||
* @param windowHeight: Dp value of the window height
|
||||
*/
|
||||
data class WindowState(
|
||||
val hasFold: Boolean = false,
|
||||
val isFoldHorizontal: Boolean = false,
|
||||
val foldBounds: Rect = Rect(),
|
||||
val foldState: FoldState = FoldState.FLAT,
|
||||
val foldSeparates: Boolean = false,
|
||||
val foldOccludes: Boolean = false,
|
||||
val windowWidth: Dp = 0.dp,
|
||||
val windowHeight: Dp = 0.dp,
|
||||
) {
|
||||
private val foldableFoldSize = when (isFoldHorizontal) {
|
||||
true -> foldBounds.height()
|
||||
false -> foldBounds.width()
|
||||
}
|
||||
|
||||
// Returns a pixel value of the width of a single pane
|
||||
val foldablePaneWidth: Int = when (isFoldHorizontal) {
|
||||
true -> foldBounds.right
|
||||
false -> foldBounds.left
|
||||
}
|
||||
|
||||
// Returns a pixel value of the width of the hinge or the folding line
|
||||
val foldSize: Int = if (hasFold) foldableFoldSize else 0
|
||||
|
||||
val windowMode: WindowMode
|
||||
@Composable get() {
|
||||
// REVISIT: should width/height ratio be used instead of orientation?
|
||||
val isPortrait =
|
||||
LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
|
||||
return calculateWindowMode(isPortrait)
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun calculateWindowMode(isPortrait: Boolean): WindowMode {
|
||||
// REVISIT: should height class also be considered?
|
||||
// Also, right now we are considering large screens + foldables mutually exclusive
|
||||
// (which seems necessary for dualscreen apps), but we may want to think about this
|
||||
// more and change our approach if we think there are cases where we want an app to
|
||||
// know about both properties
|
||||
val widthSizeClass = getWindowSizeClass(windowWidth)
|
||||
val isLargeScreen = !hasFold && widthSizeClass == WindowSizeClass.EXPANDED
|
||||
|
||||
return when {
|
||||
hasFold -> {
|
||||
if (isFoldHorizontal)
|
||||
WindowMode.DUAL_LANDSCAPE
|
||||
else
|
||||
WindowMode.DUAL_PORTRAIT
|
||||
}
|
||||
isLargeScreen -> {
|
||||
if (isPortrait)
|
||||
WindowMode.DUAL_LANDSCAPE
|
||||
else
|
||||
WindowMode.DUAL_PORTRAIT
|
||||
}
|
||||
isPortrait -> WindowMode.SINGLE_PORTRAIT
|
||||
else -> WindowMode.SINGLE_LANDSCAPE
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun isDualScreen(): Boolean {
|
||||
return windowMode.isDualScreen
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun isDualPortrait(): Boolean {
|
||||
return windowMode == WindowMode.DUAL_PORTRAIT
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun isDualLandscape(): Boolean {
|
||||
return windowMode == WindowMode.DUAL_LANDSCAPE
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun isSinglePortrait(): Boolean {
|
||||
return windowMode == WindowMode.SINGLE_PORTRAIT
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun isSingleLandscape(): Boolean {
|
||||
return windowMode == WindowMode.SINGLE_LANDSCAPE
|
||||
}
|
||||
|
||||
// return the size class (compact, medium, or expanded) for window width
|
||||
@Composable
|
||||
fun widthSizeClass(): WindowSizeClass {
|
||||
return getWindowSizeClass(windowWidth)
|
||||
}
|
||||
|
||||
// return the size class (compact, medium, or expanded) for window height
|
||||
@Composable
|
||||
fun heightSizeClass(): WindowSizeClass {
|
||||
return getWindowSizeClass(windowHeight, Dimension.HEIGHT)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Rect
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.window.layout.FoldingFeature
|
||||
import androidx.window.layout.WindowInfoTracker.Companion.getOrCreate
|
||||
import androidx.window.layout.WindowMetricsCalculator
|
||||
import kotlinx.coroutines.flow.collect
|
||||
|
||||
@Composable
|
||||
fun Activity.rememberWindowState(): WindowState {
|
||||
val windowLayoutInfo = getOrCreate(this).windowLayoutInfo(this)
|
||||
|
||||
var hasFold by remember { mutableStateOf(false) }
|
||||
var isFoldHorizontal by remember { mutableStateOf(false) }
|
||||
var foldBounds by remember { mutableStateOf(Rect()) }
|
||||
var foldState by remember { mutableStateOf(FoldState.FLAT) }
|
||||
var foldSeparates by remember { mutableStateOf(false) }
|
||||
var foldOccludes by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(windowLayoutInfo) {
|
||||
windowLayoutInfo.collect { newLayoutInfo ->
|
||||
val foldingFeature = newLayoutInfo.displayFeatures.filterIsInstance<FoldingFeature>().firstOrNull()
|
||||
foldingFeature?.let {
|
||||
hasFold = true
|
||||
isFoldHorizontal = it.orientation == FoldingFeature.Orientation.HORIZONTAL
|
||||
foldBounds = it.bounds
|
||||
foldState = when (it.state) {
|
||||
FoldingFeature.State.HALF_OPENED -> FoldState.HALF_OPENED
|
||||
else -> FoldState.FLAT
|
||||
}
|
||||
foldSeparates = it.isSeparating
|
||||
foldOccludes = it.occlusionType == FoldingFeature.OcclusionType.FULL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val config = LocalConfiguration.current
|
||||
val windowMetrics = remember(config) {
|
||||
WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(this).bounds
|
||||
}
|
||||
|
||||
val windowWidth = with(LocalDensity.current) { windowMetrics.width().toDp() }
|
||||
val windowHeight = with(LocalDensity.current) { windowMetrics.height().toDp() }
|
||||
|
||||
return WindowState(
|
||||
hasFold,
|
||||
isFoldHorizontal,
|
||||
foldBounds,
|
||||
foldState,
|
||||
foldSeparates,
|
||||
foldOccludes,
|
||||
windowWidth,
|
||||
windowHeight
|
||||
)
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Test
|
||||
|
||||
class WindowModeTest {
|
||||
@Test
|
||||
fun single_modes_are_not_dualscreen() {
|
||||
assertFalse(WindowMode.SINGLE_LANDSCAPE.isDualScreen)
|
||||
assertFalse(WindowMode.SINGLE_PORTRAIT.isDualScreen)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dual_modes_are_dualscreen() {
|
||||
assert(WindowMode.DUAL_LANDSCAPE.isDualScreen)
|
||||
assert(WindowMode.DUAL_PORTRAIT.isDualScreen)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class WindowSizeClassTest {
|
||||
@Test
|
||||
fun width_returns_compact() {
|
||||
assertEquals(WindowSizeClass.COMPACT, getWindowSizeClass(500.dp, Dimension.WIDTH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun width_returns_medium() {
|
||||
assertEquals(WindowSizeClass.MEDIUM, getWindowSizeClass(700.dp, Dimension.WIDTH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun width_returns_expanded() {
|
||||
assertEquals(WindowSizeClass.EXPANDED, getWindowSizeClass(900.dp, Dimension.WIDTH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun height_returns_compact() {
|
||||
assertEquals(WindowSizeClass.COMPACT, getWindowSizeClass(300.dp, Dimension.HEIGHT))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun height_returns_medium() {
|
||||
assertEquals(WindowSizeClass.MEDIUM, getWindowSizeClass(700.dp, Dimension.HEIGHT))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun height_returns_expanded() {
|
||||
assertEquals(WindowSizeClass.EXPANDED, getWindowSizeClass(1000.dp, Dimension.HEIGHT))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
apply plugin: 'org.jetbrains.dokka'
|
||||
|
||||
//Every module defines its own values
|
||||
group = PUBLISH_GROUP_ID
|
||||
version = LIBRARY_VERSION
|
||||
description = LIBRARY_DESCRIPTION
|
||||
|
||||
//Signing key-value pairs (used for the publication no matter the target (ADO or MavenCentral))
|
||||
ext["signing.keyId"] = getPropertyValue("SIGNING_KEY_ID")
|
||||
ext["signing.password"] = getPropertyValue("SIGNING_PASSWORD")
|
||||
ext["signing.secretKeyRingFile"] = getPropertyValue("SIGNING_SECRET_FILE")
|
||||
|
||||
//Maven central key-value pairs
|
||||
ext["mavenUser"] = getPropertyValue("MAVEN_USER")
|
||||
ext["mavenPassword"] = getPropertyValue("MAVEN_PASSWORD")
|
||||
|
||||
//ADO key-value pairs
|
||||
ext["ado_url"] = getPropertyValue("ADO_URL")
|
||||
ext["ado_user"] = getPropertyValue("ADO_USER")
|
||||
ext["ado_passwd"] = getPropertyValue("ADO_PASSWD")
|
||||
|
||||
|
||||
task androidSourcesJar(type: Jar) {
|
||||
archiveClassifier.set('sources')
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
from android.sourceSets.main.kotlin.srcDirs
|
||||
}
|
||||
|
||||
dokkaHtml.configure {
|
||||
dokkaSourceSets {
|
||||
named("main") {
|
||||
noAndroidSdkLink.set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task dokkaHtmlJar(type: Jar, dependsOn: dokkaHtml) {
|
||||
archiveClassifier.set('html-doc')
|
||||
from dokkaHtml.outputDirectory
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
SurfaceDuoCompose(MavenPublication) {
|
||||
//Define library main info. Each build.gradle library file define its own data.
|
||||
groupId PUBLISH_GROUP_ID
|
||||
artifactId PUBLISH_ARTIFACT_ID
|
||||
version it.version
|
||||
|
||||
//Set the artifact files
|
||||
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
|
||||
artifact(androidSourcesJar)
|
||||
artifact(dokkaHtmlJar)
|
||||
|
||||
pom {
|
||||
name = PUBLISH_ARTIFACT_ID
|
||||
description = LIBRARY_DESCRIPTION
|
||||
url = 'https://github.com/microsoft/surface-duo-compose-sdk'
|
||||
licenses {
|
||||
license {
|
||||
name = 'MIT'
|
||||
url = 'https://opensource.org/licenses/MIT'
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = 'MicrosoftSurfaceDuoDevX'
|
||||
name = 'Microsoft Surface Duo DevX team'
|
||||
email = 'surfaceduo-devx-libs@microsoft.com'
|
||||
}
|
||||
}
|
||||
// Version control info
|
||||
scm {
|
||||
connection = 'scm:git:github.com/microsoft/surface-duo-compose-sdk.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/microsoft/surface-duo-compose-sdk.git'
|
||||
url = 'https://github.com/microsoft/surface-duo-compose-sdk/tree/main'
|
||||
}
|
||||
// A slightly hacky fix so that your POM will include any transitive dependencies
|
||||
// that your library builds upon
|
||||
withXml {
|
||||
def dependenciesNode = asNode().appendNode('dependencies')
|
||||
project.configurations.implementation.allDependencies.each {
|
||||
def dependencyNode = dependenciesNode.appendNode('dependency')
|
||||
dependencyNode.appendNode('groupId', it.group)
|
||||
dependencyNode.appendNode('artifactId', it.name)
|
||||
dependencyNode.appendNode('version', it.version)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Public: This is used to upload the artifact to the public repository.
|
||||
//You can use it by doing: ./gradlew :module:publishSurfaceDuoComposePublicationToMavencentralRepository
|
||||
//being :module the specific module you want to create the artifact from
|
||||
repositories {
|
||||
maven {
|
||||
name = "MavenCentral"
|
||||
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
||||
credentials {
|
||||
username mavenUser
|
||||
password mavenPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Public/and for test purposes: This is used to upload the artifact to internal repository
|
||||
// for testing purposes You can use it by doing:
|
||||
// ./gradlew :module:publishSurfaceDuoSDKPublicationToADORepository
|
||||
//being :module the specific module you want to create the artifact from
|
||||
repositories {
|
||||
maven {
|
||||
name 'ADO'
|
||||
url ado_url
|
||||
credentials {
|
||||
username ado_user
|
||||
password ado_passwd
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
sign publishing.publications
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
/build
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
*
|
||||
* * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* * Licensed under the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.microsoft.device.dualscreen.windowstate"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary true
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
useIR = true
|
||||
}
|
||||
buildFeatures {
|
||||
compose true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion composeVersion
|
||||
kotlinCompilerVersion '1.5.21'
|
||||
}
|
||||
packagingOptions {
|
||||
resources {
|
||||
excludes += '/META-INF/{AL2.0,LGPL2.1}'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(path: ':library')
|
||||
|
||||
implementation kotlinDependencies.kotlinStdlib
|
||||
implementation androidxDependencies.ktxCore
|
||||
implementation androidxDependencies.appCompat
|
||||
implementation androidxDependencies.window
|
||||
implementation composeDependencies.composeUI
|
||||
implementation composeDependencies.composeMaterial
|
||||
implementation composeDependencies.composeUITooling
|
||||
implementation composeDependencies.activityCompose
|
||||
|
||||
implementation googleDependencies.material
|
||||
|
||||
androidTestImplementation(testDependencies.androidxTestCore)
|
||||
androidTestImplementation(testDependencies.androidxTestRules)
|
||||
androidTestImplementation(testDependencies.androidxTestRunner)
|
||||
androidTestImplementation(testDependencies.composeUITest)
|
||||
androidTestImplementation(testDependencies.composeJunit)
|
||||
|
||||
debugImplementation(testDependencies.composeUITestManifest)
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.microsoft.device.dualscreen.windowstate">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.WindowState">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.WindowState.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
*
|
||||
* * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* * Licensed under the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.microsoft.device.dualscreen.windowstate
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.microsoft.device.dualscreen.windowstate.ui.theme.WindowStateTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
private lateinit var windowState: WindowState
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
windowState = rememberWindowState()
|
||||
|
||||
WindowStateTheme {
|
||||
// A surface container using the 'background' color from the theme
|
||||
Surface(color = MaterialTheme.colors.background) {
|
||||
WindowStateDashboard(windowState)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun WindowStateDashboard(windowState: WindowState) {
|
||||
val foldSize = windowState.foldSize
|
||||
val foldablePaneWidth = windowState.foldablePaneWidth
|
||||
val foldSizeDp = with(LocalDensity.current) { foldSize.toDp() }
|
||||
val foldablePaneWidthDp = with(LocalDensity.current) { foldablePaneWidth.toDp() }
|
||||
|
||||
val isDualScreen = windowState.isDualScreen()
|
||||
val isDualPortrait = windowState.isDualPortrait()
|
||||
val isDualLandscape = windowState.isDualLandscape()
|
||||
val isSinglePortrait = windowState.isSinglePortrait()
|
||||
val isSingleLandscape = windowState.isSingleLandscape()
|
||||
|
||||
val widthSizeClass = windowState.widthSizeClass()
|
||||
val heightSizeClass = windowState.heightSizeClass()
|
||||
|
||||
Column {
|
||||
Text(text = "The current foldSize is ${foldSize}px, $foldSizeDp")
|
||||
Text(text = "The current foldablePaneWidth is ${foldablePaneWidth}px, $foldablePaneWidthDp")
|
||||
Spacer(modifier = Modifier.height(15.dp))
|
||||
|
||||
Text(text = "Is the app in dual screen mode? $isDualScreen")
|
||||
Text(text = "Is the app in dual portrait mode? $isDualPortrait")
|
||||
Text(text = "Is the app in dual landscape mode? $isDualLandscape")
|
||||
Text(text = "Is the app in single portrait mode? $isSinglePortrait")
|
||||
Text(text = "Is the app in single landscape mode? $isSingleLandscape")
|
||||
Spacer(modifier = Modifier.height(15.dp))
|
||||
|
||||
Text(text = "What is the current width size class? $widthSizeClass")
|
||||
Text(text = "What is the current height size class? $heightSizeClass")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.microsoft.device.dualscreen.windowstate.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val Purple200 = Color(0xFFBB86FC)
|
||||
val Purple500 = Color(0xFF6200EE)
|
||||
val Purple700 = Color(0xFF3700B3)
|
||||
val Teal200 = Color(0xFF03DAC5)
|
|
@ -0,0 +1,11 @@
|
|||
package com.microsoft.device.dualscreen.windowstate.ui.theme
|
||||
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Shapes
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
val Shapes = Shapes(
|
||||
small = RoundedCornerShape(4.dp),
|
||||
medium = RoundedCornerShape(4.dp),
|
||||
large = RoundedCornerShape(0.dp)
|
||||
)
|
|
@ -0,0 +1,35 @@
|
|||
package com.microsoft.device.dualscreen.windowstate.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.darkColors
|
||||
import androidx.compose.material.lightColors
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
private val DarkColorPalette = darkColors(
|
||||
primary = Purple200,
|
||||
primaryVariant = Purple700,
|
||||
secondary = Teal200
|
||||
)
|
||||
|
||||
private val LightColorPalette = lightColors(
|
||||
primary = Purple500,
|
||||
primaryVariant = Purple700,
|
||||
secondary = Teal200
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun WindowStateTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
|
||||
val colors = if (darkTheme) {
|
||||
DarkColorPalette
|
||||
} else {
|
||||
LightColorPalette
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colors = colors,
|
||||
typography = Typography,
|
||||
shapes = Shapes,
|
||||
content = content
|
||||
)
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.microsoft.device.dualscreen.windowstate.ui.theme
|
||||
|
||||
import androidx.compose.material.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
body1 = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp
|
||||
)
|
||||
)
|
|
@ -0,0 +1,30 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
|
@ -0,0 +1,170 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
После Ширина: | Высота: | Размер: 1.4 KiB |
После Ширина: | Высота: | Размер: 2.8 KiB |
После Ширина: | Высота: | Размер: 982 B |
После Ширина: | Высота: | Размер: 1.7 KiB |
После Ширина: | Высота: | Размер: 1.9 KiB |
После Ширина: | Высота: | Размер: 3.8 KiB |
После Ширина: | Высота: | Размер: 2.8 KiB |
После Ширина: | Высота: | Размер: 5.8 KiB |
После Ширина: | Высота: | Размер: 3.8 KiB |
После Ширина: | Высота: | Размер: 7.6 KiB |
|
@ -0,0 +1,16 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.WindowState" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_200</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/black</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">WindowStateSample</string>
|
||||
</resources>
|
|
@ -0,0 +1,25 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.WindowState" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
<style name="Theme.WindowState.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.WindowState.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="Theme.WindowState.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
</resources>
|
После Ширина: | Высота: | Размер: 55 KiB |
|
@ -0,0 +1,2 @@
|
|||
rootProject.name = "WindowState"
|
||||
include ':library', ':sample'
|