From 4a7e8b6ebab870e079be0ab644f9688ac9a8a5bc Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Sun, 19 Jan 2020 19:07:06 +0100 Subject: [PATCH] Reset state on paused to prevent layout glitches --- .../card_locker/LoyaltyCardViewActivity.java | 6 ++++++ .../card_locker/LoyaltyCardViewActivityTest.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index 30e3af167..edeaf63b9 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -145,6 +145,12 @@ public class LoyaltyCardViewActivity extends AppCompatActivity Log.i(TAG, "To view card: " + loyaltyCardId); + if(barcodeIsFullscreen) + { + // Properly reset state to prevent any issues + recreate(); + } + // The brightness value is on a scale from [0, ..., 1], where // '1' is the brightest. We attempt to maximize the brightness // to help barcode readers scan the barcode. diff --git a/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java b/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java index 4c45e3cca..230870f34 100644 --- a/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java +++ b/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java @@ -738,6 +738,21 @@ public class LoyaltyCardViewActivityTest assertEquals(uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN, uiOptions); assertEquals(View.GONE, collapsingToolbarLayout.getVisibility()); + // Resuming the activity should revert the state to normal view + activityController.pause(); + activityController.resume(); + uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); + assertNotEquals(uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY, uiOptions); + assertNotEquals(uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN, uiOptions); + assertEquals(View.VISIBLE, collapsingToolbarLayout.getVisibility()); + + // Clicking the barcode should still work to fullscreen again + barcodeImage.performClick(); + uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); + assertEquals(uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY, uiOptions); + assertEquals(uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN, uiOptions); + assertEquals(View.GONE, collapsingToolbarLayout.getVisibility()); + // In full screen mode, back button should disable fullscreen activity.onBackPressed(); uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility();