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

[Android] Stage fullscreen issue when image is displayed by file.openWithDefaultApplication #3569

Open
2jfw opened this issue Nov 11, 2024 · 13 comments
Labels

Comments

@2jfw
Copy link

2jfw commented Nov 11, 2024

Attached is a sample project for Android with the following scenario:

Enviroment:

  • AIR SDK 51.1.2.1
  • Android 10 (Sony H8314)

Application:

  • App is not in fullscreen mode (stage.displayState = StageDisplayState.NORMAL)

Issue and how to reproduce:

  • An image is opened with file.openWithDefaultApplication
  • The image will be shown by the internal image viewer which seems to be "embedded" (or displayed) within the AIR app; there is no extra app or window present in Android. The image is automatically displayed in fullscreen mode, fading out the top and bottom toolbar upon opening
  • The stage size will change as the image gets displayed in that fullscreen mode by Android (/this is actually undesired behavior)
  • Stage event listener Event.RESIZE will trigger whereas Event.FULLSCREEN will not
  • Use the hardware "Home" button to go back to OS layer or use the one to open another app when the image is open

Actual issue:

  • Then going back to the AIR app will result in the app regulary being display in a "pseudo" fullscreenmode, meaning the status bars (top, bottom) are hidden and the application covers the entire screen. Traces show that the stage display mode has not changed but the stage dimensions have (in that case the height equals the fullscreen height).
  • Repeating that one or many times will lead to the toolbars to re-appear and the pseudo fullscreen mode may vanishes, but the stage then is covered by the top and bottom status bars, as if it still was in fullscreen mode
  • It never recovers unless you manually change the stage.displayState to fullscreen and back

What it looks like in the end:
Screenshot_20241111-204625

Sample project:
FullscreenIssue.zip

Source:

package
{

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PNGEncoderOptions;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.ByteArray;
	import flash.utils.setTimeout;


	[SWF(frameRate="60", backgroundColor="0x222222")]
	public class FullscreenIssue extends Sprite
	{
		[Embed(source="../assets/image.png")]
		private static const IMAGE : Class;

		private var _imageFile : File;


		public function FullscreenIssue()
		{
			stage.align        = StageAlign.TOP_LEFT;
			stage.scaleMode    = StageScaleMode.NO_SCALE;
			stage.displayState = StageDisplayState.NORMAL;

			File.applicationStorageDirectory.requestPermission();

			createHint();
			addEventListeners();
		}


		private function createHint() : void
		{
			var textField : TextField = new TextField();
			textField.text            = "Click stage to open image";
			textField.width           = 1000;
			textField.height          = 100;

			var textFormat : TextFormat = new TextFormat();
			textFormat.size             = 100; // intentionally chosen so high to show actual cut off/overlay
			textFormat.color            = 0x999999;
			textField.setTextFormat(textFormat);

			addChild(textField);
		}


		private function addEventListeners() : void
		{
			stage.addEventListener(MouseEvent.CLICK,
			                       onClickStage);

			stage.addEventListener(Event.RESIZE,
			                       onResizeStage);

			stage.addEventListener(Event.FULLSCREEN,
			                       onChangeFullscreenMode);
		}


		private function onClickStage(event : MouseEvent) : void
		{
			trace("Click");

			var fileStream : FileStream = new FileStream();
			_imageFile                  = File.applicationStorageDirectory.resolvePath("image.png");

			if (!_imageFile || !_imageFile.exists)
			{
				try
				{
					var bitmapData : BitmapData = ((new IMAGE) as Bitmap).bitmapData;

					fileStream.open(_imageFile,
					                FileMode.WRITE);

					var byteArray : ByteArray = bitmapData.encode(new Rectangle(0,
					                                                            0,
					                                                            bitmapData.width,
					                                                            bitmapData.height),
					                                              new PNGEncoderOptions());

					fileStream.writeBytes(byteArray,
					                      0,
					                      byteArray.length);

					fileStream.close();
				}
				catch (error : Error)
				{
					trace("ERROR");
				}
			}

			_imageFile.openWithDefaultApplication();


			setTimeout(function () : void {
				           showDebugTraces("onClickStage");
			           },
			           1000);
		}


		private function onResizeStage(event : Event) : void
		{
			showDebugTraces("onResizeStage");
		}


		private function onChangeFullscreenMode(event : Event) : void
		{
			// Will never trigger though stage may "optically" be in fullscreen mode and
			// cover entire screen. No status bars visible any longer

			showDebugTraces("onChangeFullscreenMode");
		}


		private function showDebugTraces(source : String) : void
		{
			trace(source,
			      stage.stageWidth,
			      stage.stageHeight,
			      stage.displayState);
		}
	}
}
@2jfw 2jfw added the Bug label Nov 11, 2024
@2jfw
Copy link
Author

2jfw commented Nov 19, 2024

Would it be possible to have a look at the resize behavior here @ajwfrost ?

@2jfw
Copy link
Author

2jfw commented Nov 25, 2024

Any news on the stage resize issue?

@ajwfrost
Copy link
Collaborator

We've not been able to reproduce this one here .. although I noticed you've got Android 10 listed there. I'll see if we can dig out an older phone to check it.

One thing I wondered though: you mention opening the image using the default application: to start with, we get a list of options here because of how the Android intents are set up. Do you know if your scenario reproduces if you have the options, or is it going directly to a gallery-type view? And can you check in the settings whether the gallery/photos app is set up with a full-screen mode setting?

thanks

@2jfw
Copy link
Author

2jfw commented Nov 26, 2024

We've not been able to reproduce this one here .. although I noticed you've got Android 10 listed there. I'll see if we can dig out an older phone to check it.

This would be great, thanks!

Do you know if your scenario reproduces if you have the options, or is it going directly to a gallery-type view?

There is no option I can chose from - opening the image with the default app immediately opens a fullscreen gallery-type view inside the AIR application. It has no extra window (and thus causes the AIR app to also go fullscreen).
I have not seen this kind of "reduced" viewer on my phone before. Basically it equals the default gallery viewer when an image is clicked. In the AIR app, the viewer only has a back button at the top left corner and a "Kebab" menu (three dots) at the top right corner. Inside the Kebab menu there is only one option to "Save". Swiping left or right on the image will cause a glow effect to occur (probably the indication there are no other images to show to the left/right).

And can you check in the settings whether the gallery/photos app is set up with a full-screen mode setting?

I'm actually unable to find any setting which could be related to this. I would assume my phone (/Android) has no such general settings for apps at all. Never saw anything related to fullscreen so far.

@2jfw
Copy link
Author

2jfw commented Dec 11, 2024

Any update or info on this fullscreen issue?

@ajwfrost
Copy link
Collaborator

Hi

We'd tried in an older Samsung S8 (Android 9) and an LG (Android 10) but still no reproduction. Looking at your description, the one extra step we seem to have to make is when the image first opens in the phone's default image-viewer activity: these are not opening in full-screen mode. If you tap on the image after it's opened, they typically then fade out the status bar/button bar. But your description has the second bullet which suggests this automatically happens when the other activity is opened.

So this might be something Sony-specific. I had a feeling we did have a Sony handset somewhere, I will try to find out who has that!

In the meantime though: are you able to send a log of the resize and any activate/fullscreen/orientation events that are sent, and to distinguish when these are happening? We may be able to try to detect this scenario and work around it somehow, or at least provide enough information that you would be able to catch this and manually resize the window.

thanks

@2jfw
Copy link
Author

2jfw commented Dec 11, 2024

Thanks for your update!

But your description has the second bullet which suggests this automatically happens when the other activity is opened.

Yes, exactly - it's one go with the fullscreen: the image viewer opens and immediately overlays the entire screen (black background) and at the same time the status bars top/bottom tween out.
I will create a log where we can see what events are dispatched/event listeners are triggered and at what time.
The sample from above already contains some info; Event.RESIZE gets triggered, Event.FULLSCREEN does not get triggered when entering fullscreen. Exiting the image viewer will not trigger and Event.RESIZE so the stage sticks to fullscreen width/height.

@ajwfrost
Copy link
Collaborator

FYI we found a Sony handset (Xperia 5 III) but it has Android 13 on it. When the PNG is opened, it's not full screen, and we again can't reproduce it.

Just checking, do you know what actual app the PNG opens in? When I click on the PNG, it seems to be in the "Photos" app, it has icons near the bottom saying "Share" and "Lens" which is what I also get if I manually open Google Photos and click on a photo (well, then I also get Edit and Delete options, but it's basically the same activity).

thanks

@2jfw
Copy link
Author

2jfw commented Dec 12, 2024

The PNG is opened with the same view as if you would select it from within the "Albums" app (The app with the orange landscape image https://images.app.goo.gl/Wpc1Ty59tzBSDzSf6). When opened from the AIR app, it is the same view but does not contain all the UI elements:

In the AIR app, the viewer only has a back button at the top left corner and a "Kebab" menu (three dots) at the top right corner. Inside the Kebab menu there is only one option to "Save". Swiping left or right on the image will cause a glow effect to occur (probably the indication there are no other images to show to the left/right).

The view of the image, which gets opened from default albums app (not AIR) has the same behavior as in the AIR app: it will go fullscreen and fade out the control bars (top/bottom) so you will initially only see the image fullscreen without any UI elements. Clicking on the image then will reveal the UI elements (status bars, 3-button default Android navigation (with the "back" button etc) and also the buttons to share, edit or delete at the bottom, the back button at the top left and the kebab menu at the top right. (Sorry, I can currently not share a screenshot, which would make things easier to see/understand).

App seems to be called "Sony Album" (I'm having version 9.8.A.1.2 on my phone).

There seems to be an APK available here from here:
https%3A%2F%2Fwww.apkmirror.com%2Fapk%2Fsony-mobile-communications%2Falbum%2Falbum-9-2-a-0-8-release%2F

However, unsure about the website hosting this (may contain a risk..)

@ajwfrost
Copy link
Collaborator

Ah - great, so I have managed to download and install the "Albums" application and set this up as the default. And now we have just reproduced it...! This is on the Sony Xperia, Android 13... I guess some side-effect of the interactions between the different applications/views.

We should be able to take it from here, thanks for your patience! :-)

@2jfw
Copy link
Author

2jfw commented Dec 12, 2024

Ah, very good! 😀
Thank you so much!

@2jfw
Copy link
Author

2jfw commented Dec 12, 2024

Side Note: Thinking about this, the issue may be a bit more "large-scale" than just with this specific image viewer. Basically, opening anything with an app that goes fullscreen, would/could cause this, right?

I never tested it but are all apps, when using openWithDefaultApplication, opened within the scope of the AIR app and do not appear as a stand-alone app?

@ajwfrost
Copy link
Collaborator

I guess anything that pushes the app into a full-screen mode may cause the same problem, yes. I think we will need to just check for this and dispatch the full screen event. Although it sounds like we need to check for some other odd behaviour:

Repeating that one or many times will lead to the toolbars to re-appear and the pseudo fullscreen mode may vanishes, but the stage then is covered by the top and bottom status bars, as if it still was in fullscreen mode

In terms of openWithDefaultApplication, I think it's just dependent on what the handling application decides to do. We're basically launching the intent ACTION_VIEW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants