Android Question [Solved] Galaxy Z flip 5 issue

wes58

Active Member
Licensed User
Longtime User
I have a Galaxy Z Flip 5 and found the issue with scaling.
The phone has to screens - main an cover screen.
Main Screen: 6.7 inches, Resolution 1080 x 2640 pixels (~425 ppi density)
Cover display: 3.4 inches, Resolution 720 x 748 pixels, 306 ppi

The application uses 2 CLVs and the issue is like this:
When I install application (or run for the firs time after restart) with the phone closed, the application looks fine on the cover screen. But after opening the phone, the app on the main screen is not scaled correctly - see attached picture capture1.png

And the opposite thing happens when install application (or run for the firs time after restart) with the phone open. On the main screen everything looks OK, but when I close the phone and start application on cover screen - it is not scaled correctly - see second picture capture2.png.

It looks like the application keeps the screen density from the first opened screen on the second screen.
I tried different things, using even Activity.finish but this doesn't change anything

Any suggestions how to fix this are welcomed.
 

Attachments

  • capture2.png
    capture2.png
    64.9 KB · Views: 131
  • capture1.png
    capture1.png
    35.3 KB · Views: 116

wes58

Active Member
Licensed User
Longtime User
After spending more time, I have found out how to fix this.
If you add a layout to the CLV item, you have to define in the variant/general script for the layout, position and size of any view that is on the layout - i.e. labels, ImageViews, etc.
Now it is going to take me a lot of time to do it.
Is there any better solution?
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
I have been trying to find out why I had to define values for each view in the general script. I had a look at generated main.java and saw this:
Java:
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mostCurrent = this;
        if (processBA == null) {
            processBA = new BA(this.getApplicationContext(), null, null, "com.homehub", "com.homehub.main");
            processBA.loadHtSubs(this.getClass());
            float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
            BALayout.setDeviceScale(deviceScale);
            
        }
        else if (previousOne != null) {
            Activity p = previousOne.get();
            if (p != null && p != this) {
                BA.LogInfo("Killing previous instance (main).");
                p.finish();
            }
        }
        processBA.setActivityPaused(true);
        processBA.runHook("oncreate", this, null);
        if (!includeTitle) {
            this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
        }
        if (fullScreen) {
            getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                    android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        
        processBA.sharedProcessBA.activityBA = null;
        layout = new BALayout(this);
        setContentView(layout);
Device scale is only checked if processBA == null.
Is that the reason, why even though device density is changed (using cover screen then main screen or vice versa), density is not changed in the BALayout?
How could I check and set device scale always? I would like to see if this works?
This would be something worth looking at, since there are a couple of different foldable devices on the market now!

This is I guess, question for @Erel since he generates this part of main.java.
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
I have tested it by moving code to set device scale after if-endif, and it works fine now, without a need to set position and size of views in the script
Java:
            float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
            BALayout.setDeviceScale(deviceScale);
I realised that Erel can't help me since I am using version 11.5 of B4A. And I can't use version 12.xx because it is not backwards compatible - i.e. I can't compile my application because I am using services for widget and FCM.
So, the only way I can do it is to modify the application after build.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
I can't use version 12.xx because it is not backwards compatible
AFAIK B4A is always backward compatible. Maybe some library not updated for Android latest version.
Always advised to use latest B4A as it has all required Android features.
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
Although I marked the thread as SOLVED, it is really a Band-Aid not a fix, so I can have my application running.
It is really disappointing that a week after my first post, there was no comment, zero interest, no suggestion how to fix it from Erel. Even though I pointed out where the problem is with his internal code generated by the compiler.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
I think Erel needs the flip phone to debug and fix the issue.
You can also pm him on this matter.
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
I think Erel needs the flip phone to debug and fix the issue.
You can also pm him on this matter.
There is nothing special about the phone - it has 2 displays.
Android Developer site - App continuity

App continuity refers to the capability of an app to seamlessly restore the user state when
it receives a configuration change, such as when a device is folded or unfolded. Since an app
running on a foldable device can transition from one screen to another, it is very important
that the current task continues seamlessly after the transition and the app remains the same
state and location.
When the system will trigger a configuration change during the transition, an app should save
the UI state and support configuration changes gracefully.

Foldable devices bring different screen size and shape to the market. Hence, the way people
use your app may vary from past years. By considering new layouts and navigation patterns,
app developers can explore opportunities to build greater experience in larger screen
devices.
Handle diverse aspect ratios

On devices where your application takes up the entire screen, large-screen form factors mean
you need to allow for various aspect ratios. For example, in the Samsung Z fold series, the
aspect ratio of the cover screen is similar to a bar-type device, whereas the ratio of the
main screen is close to square. Take a communication app, users may place it in a tall,
narrow window at the edge of the screen so they can view and respond to messages while
working with another app that occupies the rest of the screen.
I showed where an issue is with internal code generated by the compiler.
It doesn't look at density (change) when the phone is opened or closed and the app is used on main screen or cover screen!
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
I have realised that I can hook into onCreate process by adding the code like this:
Java:
#If Java
public void _onCreate(){
      float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
      BALayout.setDeviceScale(deviceScale);
      BA.LogInfo("** deviceScale " + deviceScale);
      return;
}
#End If
Everything works fine now.
In the log I get with the phone closed, on cover screen - ** deviceScale 1.75
With the phone open, main screen - ** deviceScale 3.0
And now, I don't have to change anything after compilation.
 
Upvote 0
Top