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-24570] Android: Fix screen density breaking changes + multi-window in Android 7.0 #8970
Conversation
Object.keys(finalAndroidManifest.application.activity).forEach(function (name) { | ||
var activity = finalAndroidManifest.application.activity[name]; | ||
if (!activity.configChanges) { | ||
activity.configChanges = ['density']; |
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.
Is density
the only possible value in configChanges
? Otherwise it would break other configs. And we should warn them to put it there if they don't do so far.
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.
No, there other values that go into configChanges
but it is a requirement for consistency across different Android 7 devices for screen magnification. For activity.configChanges = ['density'];
I used the same logic used elsewhere just in case a situation arises where configChanges
is empty but the fact is screenSize
will always be added to configChanges
so it is kind of redundant in a way.
Also, I should make users aware that density
is added by default?
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.
The "density" configChange should always be injected into the AndroidManifest.xml for every activity when targeting Android 7.0 or higher.
If we do not add this configChange setting, then a Titanium activity's UI will disappear if the end-user changes the "Display Size" under Android's main "Settings/Display" screen.
The reason this happens is because apps targeting Android 7.0 (or higher) are expected to handle "Display Size" changes dynamically. If we do not override the "density" configChange, then the activity's onCreate() method will be called, which will wipe the UI we were previously displaying (the same behavior you would see if you were missing the "screenOrientation" configChange and you rotated the screen). Apps targeting an older OS version (ie: API Level) are force-quit and restarted instead when the "Display Size" changes.
@fmerzadyan, can you double check if Titanium's JavaScript APIs correctly report the new "Display Size" set under Android "Settings/Display" please? Setting the "Display Size" to a larger setting will lower the DPI. For example, "xxxhdpi" to "mdpi" when setting it to the largest setting. We need to make sure that we're not caching the above properties since they can change dynamically now. |
@cb1kenobi, just to double check, is this the best way to inject this attribute setting to all activities in the AndroidManifest.xml file if the API Level is >= 24? |
71cf57f
to
63f946e
Compare
34a07e7
to
9ed6cea
Compare
default : | ||
return "medium"; | ||
return "unknown"; |
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.
I gave you bad advise. It should not return "unknown". Developers use this name to load images of an appropriate size based on the "density" name property. So, this code needs to be changed to use >= checks. It should also not return "medium" for unknown densities either.
The code should be changed to something like this...
public String getDensity() {
synchronized(dm) {
getDisplay().getMetrics(dm);
int dpi = dm.densityDpi;
if (dpi >= 560) { // DisplayMetrics.DENSITY_560
return "xxxhigh";
} else if (dpi >= 400) { // DisplayMetrics.DENSITY_400
return "xxhigh";
} else if (dpi >= 280) { // DisplayMetrics.DENSITY_280
return "xhigh";
} else if (dpi >= DisplayMetrics.DENSITY_HIGH) {
return "high";
} else if (dpi >= DisplayMetrics.DENSITY_TV) {
return "tvdpi";
} else if (dpi >= DisplayMetrics.DENSITY_MEDIUM) {
return "medium";
}
return "low";
}
}
android/cli/commands/_build.js
Outdated
if (this.realTargetSDK >= 13) { | ||
if (this.realTargetSDK >= 24 && !finalAndroidManifest.application.hasOwnProperty('resizeableActivity')) { | ||
finalAndroidManifest.application.resizeableActivity = true; | ||
} |
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.
Let's remove this from "_build.js". We don't want to force developers to use "resizeableActivity" in case they have layout issues when sized too small in a split-screen window... in which case they can opt-out by setting this attribute to false in the "tiapp.xml" file.
^ Never mind. Your code is checking for the existence of the property. It's doing it right.
c65e317
to
7266e2b
Compare
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.
Approved
7a84396
to
49942ca
Compare
@fmerzadyan , I am seeing an issue where app built with this fix has an invalid
This is causing the app to get installed but not launch or show up in the apps list on the device. Studio Ver: 4.9.0.201705302345 |
…ndow in Android 7.0
49942ca
to
6eeb715
Compare
FR Passed. The app switches as expected to split screen to normal mode & vice versa. Also, changing the display size in the settings appropriately reflects the change in the app but, this change is only seen when the app is restarted & not when the app is resumed from paused state or from background. Studio Ver: 4.9.1.201707130742 |
Test Case:
Add this to
tiapp.xml
in your Titanium app directory.In
titanium_mobile/build
directory, run:node scons.js build && node scons.js package && node scons.js install
. In your Titanium app, run andcat build/android/AndroidManifest.xml
. Watch out fordensity
flag inconfigChange
attribute. Verify new flags are present. Then put window in split screen mode.JIRA: https://jira.appcelerator.org/browse/TIMOB-24570