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
[TIMOB-19878] Orientation Change is not correctly detected on Android #9525
Conversation
[TIMOB-7618] Android: Text field loses focus when changing orientation Update TiTableView.java
…ientation" This reverts commit 1a5ecad.
Thank you for fixing this. |
This change collides with TIMOB-24537 which we haven't done yet. The issue here is that there is a platform parity issue. The orientation returned by iOS and Windows Phone is the device orientation, but Android returns the app's orientation. This is something we document, but we were planning on changing in Titanium 7.0.0 since it is a breaking change. Providing an app orientation is not that useful to a developer because they can already determine this by comparing the window's width/height and listening to the Window's "postlayout" event. But as it stands now, developers have no means of detecting device orientation on Android. What really needs to be changed is our |
Also note that we need to test on a large Android tablet since these devices typically have an "upright" orientation of "landscape". Meaning that the Java Edit:
|
We also need to test split-screen mode on Android 7 or higher. The reason the old |
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should revert the TiOrientationHelper
code back to what it was originally because we still need the width/height check for large Android tablets whose ROTATION_0
is landscape. We also should not use orientation
and isPublic
globals.
So, revert this file and add the following new function...
public static int getWindowTiOrientationModeFrom(Activity activty)
{
int orientation = ORIENTATION_UNKNOWN;
if (activity != null) {
WindowManager windowManager = activity.getWindowManager();
if (windowManager != null) {
Display display = windowManager.getDefaultDisplay();
if (display != null) {
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
orientation = convertRotationToTiOrientationMode(
display.getRotation(), dm.widthPixels, dm.heightPixels);
}
}
}
return orientation;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that I call the new method getWindowTiOrientationModeFrom()
to specify that it's fetching the orientation of the application window. In 7.0.0, we'll look into fetching device orientation, but it may still be useful to know the window orientation as well for our own internal purposes.
int width = dm.widthPixels; | ||
int height = dm.heightPixels; | ||
return TiOrientationHelper.convertRotationToTiOrientationMode(display.getRotation(), width, height); | ||
return TiOrientationHelper.orientation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the isPortrait()
, isLandscape()
, getPortrait()
, getLandscape()
, and getOrientation()
methods to use the new TiOrientationHelper.getWindowTiOrientationModeFrom()
method I've suggested in my comments below. We want to calculate it everytime and not depend on external code to do it for us via globals.
You're definitely correct in removing usage of the getConfiguration()
method call since that will fail to report orientation changes between "landscapeLeft" -> "landscapeRight" and vice-versa (this is by Google's design).
So, a call to isPortrait()
should look like this...
public boolean isPortrait()
{
Activity activity = TiApplication.getAppRootOrCurrentActivity();
int orientation = TiOrientationHelper.getWindowTiOrientationModeFrom(activity);
return (orientation == ORIENTATION_PORTRAIT) || (orientation == ORIENTATION_PORTRAIT_REVERSE);
}
And a call to isLandscape()
should look something like this...
public boolean isLandscape()
{
Activity activity = TiApplication.getAppRootOrCurrentActivity();
int orientation = TiOrientationHelper.getWindowTiOrientationModeFrom(activity);
return (orientation == ORIENTATION_LANDSCAPE) || (orientation == ORIENTATION_LANDSCAPE_REVERSE);
}
Closing this PR in favor of #9585 which includes above mentioned breaking change from app orientation to device orientation. (Will match iOS and Windows' behavior.) |
JIRA: https://jira.appcelerator.org/browse/TIMOB-19878
Test case: