How to detect full screen gesture mode in Mi devices programmatically - android

I am writing an Android application that needs to calculate the height of screen to display content correctly. But the height I got in Mi devices (Mi 9 SE) wasn't correct when switching to full screen gesture mode.
How can I get the real height of the screen, or check if user turned on full screen gesture mode in Mi devices?
I have tried these suggestions.
How to detect full screen gesture mode in android Q
Android: detect navigation bar visibility
Check for navigation bar

After searching and experimenting, I have found the only solution: How to detect full screen gesture mode in android Q.
Instead of using ViewCompat.setOnApplyWindowInsetsListener() function, I just have to create a WindowInsets instance for the current context, then check the getSystemGestureInsets() for each edges. This is how I implemented to make a React Native's native module.
If you need a listener to detect every changes, the solution above has done well on Android app. If you want this listener for React Native, you might want to find another approach, since I haven't made it work.

A very simpler answer:
Don't use DisplayMetrics. Just make any view take full width and height of the screen (MATCH_PARENT) then get it's dimensions, it well give accurate numbers.

Related

How can we get the size of screen with notch on the top

There are some devices such as Huawei p20(running android 8,8.1) which has in-built notch on the top.
The current way to get the size of the screen is
Display display = getWindow().getWindowManager().getDefaultDisplay();
Point screenSize = new Point();
display.getRealSize(screenSize);
//screenSize.x
//screenSize.y
And it's leading the game out of screen. So, is there any way to solve notch issue with android P and Pre-p devices.
The status bar(where all your notifications are) always adjusts to the depth of the notch. Look at the pixel 3 which has the largest notch in the world :p The status bar becomes as tall as the notch.
So the notch is only a problem if your app is in a full screen(content draws underneath the status bar) and it may cover some of your content.
Make your app non-full screen (only draw below the status bar) and you don't have to worry about any notch size in the future. A lot of games ignore the status bar from their content.
There are only a few android devices with notch option and currently it is not possible to get the exact screen size of such devices using Android APIs.
BUT there is a work around, you can check the name of device and adjust your layout accordingly.
There is one popular Android library to get the market name of an Android device. Check more information here : https://github.com/jaredrummler/AndroidDeviceNames
How to use this lib:
String deviceName = DeviceName.getDeviceName();
Hope this will help you to focus on your development instead of wasting time!

Android: control behaviour of homescreen rotation

Is there any way I can achieve the desired behaviour on rotation of the device, as illustrated in the following sketch (the wavy thing is a widget). Most likely this is something that would be controlled by the launcher, rather than controlled programmatically from any one app -- if so, is there any launcher that allows this?
Basically the reason I'm asking is because I want the widget to behave as illustrated (the widget is what I'm coding), even when the user's device is set to rotate the home screen on device rotation. Basically the only way I can see this working is if the grid layout is fixed relative to the physical screen, with the app icons just rotating within their box, and the widgets either updating their content for the new layout, or just keeping the previous content (so that the content rotates with the screen).
For updating of widget content, is there any way of detecting screen home screen rotation programmatically (different to screen rotation, since the home screen may not rotate)? This is relevant to me even for the "what I get" scenario, because the aspect ratio of the widget seems to change when the home screen is rotated, and I need to detect this and update the widget content to fit better.
dfdd
Use:
1. layout-sw480dp
2. layout-sw600dp
3. layout-sw720dp
You are unlikely to find a solution for this as the home screen (launcher) varies wildly in implementation. Many launchers don't support landscape orientation, and expecting the launcher to accommodate a widget which can expand in two different directions is simply asking too much of them.
For the launchers which do support landscape orientation, the widget should be repositioned for free without effort on your part. You may wish to detect which orientation the widget is in (such as via getResources().getConfiguration().orientation) when your provider is choosing a layout, setting up views etc, but that's about it.

AIR - Get SoftKeyboard Screen Size

In my AIR mobile application I am trying to resize my application when the softkeyboard is activated so that the bottom of my application will not be covered by the keyboard. From what I have read this is suppose to be the default behavior but I have never been able to get it to work and I have tried everything I have found online, instead the keyboard overlays ontop of the application.
I then decided I would resize my application myself based on the height and y position of the softkeyboard only to find out that the built in AIR methods for determining the height and y position of the keyboard are not correct (YAY). I even tried using a 3rd party ANE for determining the screen height by FreshPlanet and their code does not always return correct values either. I feel like this shouldn't be that hard to figure out but I am stuck. Please help!
TLDR:
How can I resize my application to be the remaining screen space when the softkeyboard is activated?
What renderMode are you using? (in manifest.xml) I found that only cpu is working to get the correct keyboard height.
Also try to set softKeyboardBehavior to none: <softKeyboardBehavior>none</softKeyboardBehavior>

Android SoftKeyboardDetect: Ignore this event what does it mean?

I see this debug message frequently in LogCat. When doing swipe or rotating the device for example. The emulator doesn't react to the events then. What does it mean?
In need to test rotation on the emulator but on some versions, when I press CTRL F12 or CTRL F11 nothing happens (well, the device rotates as a whole but not the screen) and I see this message in log. I don't find anything with google either...
Ok, it's PhoneGap specific. I found something in the source code of PhoneGap:
/**
* We are providing this class to detect when the soft keyboard is shown
* and hidden in the web view.
*/
class LinearLayoutSoftKeyboardDetect extends LinearLayout {
private static final String TAG = "SoftKeyboardDetect";
But I'm not doing anything with soft keyboard, I'm just rotating the device. It's a bug maybe?
I can give you the background on this log. There is a bug in Android or maybe they'd call it a lack of feature but there is no event thrown when the keyboard is shown or goes away. This causes a problem for web applications as the keyboard shortens the the screen size. When the screen size becomes smaller then your UI suffers.
In order to be able to react to the keyboard show/hide in PhoneGap Android we implemented the LinearLayoutSoftKeyboardDetect which is basically a LinearLayout but it reacts to changes in the screen size. If you rotate the device the width becomes the height and we can ignore the change but if the height gets dramatically smaller while the width remains the same it is safe to assume there is a keyboard being shown and we throw a show keyboard event. When the height gets dramatically larger while width stays the same we throw a hide keyboard event. Make sense?
This implementation seems affect with the situation -> When native keyboard is pop up it shrink the webview in phonegap. Again demention changes. So it tends to ignore necessary events. I want to detect native keyboard done button press event.

Android: programmatically get position of the widget on desktop relative to other widgets

On Android the user can place a widget on the desktop and then to move it by long touch and moving the finger while still holding.
Is it possible to programmatically get the position on the screen where the widget was moved by long touch?
I need my desktop widget to know if it's near the edge of the screen of the device. Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen.
I would expect that this position is not given in pixels, but as pair of 0-based indexes. E.g. if the device can display 4x7 cells on the desktop, the widget in the bottom-right corner should have coords (3, 6). Also it should be somehow possible to ask the device how many cells fit into the screen.
Or am I misunderstanding something?
On Android 2.1 and later, with some select home screens, you can find out where an app widget resides when it is clicked via getSourceBounds() -- this value is attached to any Intent you spawn via a PendingIntent via setOnClickPendingIntent().
However:
this only works on Android 2.1 and newer
not all home screens might do this, as this is part of the Launcher code IIRC
the coordinates are in pixels IIRC
there is no way to interrogate the home screen to find out this information any other way, since there is no API to interact with the home screen
Hence, I think your stated goal ("Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen") is impossible, I think.

Categories

Resources