Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace display mask lib with androidx.window:window #2569

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ dependencies {

implementation "androidx.datastore:datastore-preferences:$rootProject.ext.jetpackDataStoreVersion"

implementation(group: 'com.microsoft.device.display', name: 'display-mask', version: '0.3.0')
implementation "androidx.window:window:1.3.0"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'

implementation 'org.apache.httpcomponents.core5:httpcore5:5.3'
implementation "com.nimbusds:nimbus-jose-jwt:$rootProject.ext.nimbusVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;
import androidx.window.layout.WindowMetricsCalculator;

import com.microsoft.device.display.DisplayMask;
import com.microsoft.identity.common.R;

import java.util.List;

// This activity readjusts its child layouts so that they're displayed on both single-screen and dual-screen device correctly.
public class DualScreenActivity extends FragmentActivity {

Expand Down Expand Up @@ -165,30 +163,29 @@ private boolean isDualScreenDevice(final Context context) {
final String feature = "com.microsoft.device.display.displaymask";
final PackageManager pm = context.getPackageManager();

if (pm.hasSystemFeature(feature)) {
return true;
} else {
return false;
}
return pm.hasSystemFeature(feature);
}

/**
* Returns the area of the display that is not functional for displaying content.
*
* @param Context
* @param context Context
* @param rotation Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180 or Surface.ROTATION_270
*/
private Rect getHinge(final Context context,
int rotation) {
// Hinge's coordinates of its 4 edges in different mode
// Double Landscape Rect(0, 1350 - 1800, 1434)
// Double Portrait Rect(1350, 0 - 1434, 1800)
final DisplayMask displayMask = DisplayMask.fromResourcesRect(context);
List<Rect> boundings = displayMask.getBoundingRectsForRotation(rotation);
if (boundings.size() == 0) {
return new Rect(0, 0, 0, 0);
private Rect getHinge(final Context context, final int rotation) {
final Rect bounds = WindowMetricsCalculator
.getOrCreate()
.computeCurrentWindowMetrics(context)
.getBounds();
switch (rotation) {
case Surface.ROTATION_90:
case Surface.ROTATION_270:
return new Rect(0, 0, bounds.height(), bounds.width()); // Swap width and height for 90/270
case Surface.ROTATION_0:
case Surface.ROTATION_180:
default:
return new Rect(0, 0, bounds.width(), bounds.height()); // Original dimensions for 0/180
}
return boundings.get(0);
}

/**
Expand Down
Loading