Ok, I'm using the new Picture in Picture (PIP) mode for Oreo with a custom aspect ratio that I calculate with this:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x + (size.x / 2);
int height = size.y;
Rational aspectRatio = new Rational(width, height);
PictureInPictureParams.Builder PIPParamsBuilder = new PictureInPictureParams.Builder();
PIPParamsBuilder.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(PIPParamsBuilder.build());
Basically it gives me a bit larger width than the default one. My problem is, when I used the same code in landscape mode, I get this error:
java.lang.IllegalArgumentException: enterPictureInPictureMode: Aspect ratio is too extreme (must be between 0,418410 and 2,390000).
at android.os.Parcel.readException(Parcel.java:1946)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.IActivityManager$Stub$Proxy.enterPictureInPictureMode(IActivityManager.java:9750)
at android.app.Activity.enterPictureInPictureMode(Activity.java:2119)
at com.brickx.creartup.Main.startPIP(Main.java:740)
at com.brickx.creartup.Main.onUserLeaveHint(Main.java:751)
at android.app.Activity.performUserLeaving(Activity.java:7151)
at android.app.Instrumentation.callActivityOnUserLeaving(Instrumentation.java:1572)
at android.app.ActivityThread.performUserLeavingActivity(ActivityThread.java:4082)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4058)
at android.app.ActivityThread.-wrap15(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1700)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
The logs are pretty explicit: my aspect ratio exceeds the maximum.
But my question is: Why do I have to handle this? Can't Android set the width and/or height to the respective maximum automatically if it exceeds it?
Maybe I'm missing something here, but I think I shouldn't check the width of the device each time I enter PIP just in case it exceeds the maximum...
I assume, that this restriction was brought due to the fact, that anything with aspect ration below 0.5 and above 2.5 (roughly) will be unpractical or unpleasant to use, since it takes space on the screen, and user should be able to swipe/tap on it.
For example, if you were allowed to set aspect ratio of 0.01, it's width would be 1 pixel, and it'd be literally impossible for the user to interact with the view.