fixed the random zero insets on Android 15 properly this time
This commit is contained in:
parent
9e4658d405
commit
ade7075fd7
5 changed files with 41 additions and 18 deletions
|
|
@ -21,6 +21,8 @@ import io.github.sspanak.tt9.ui.main.keys.SoftKey;
|
|||
import io.github.sspanak.tt9.util.ThemedContextBuilder;
|
||||
|
||||
abstract class BaseMainLayout {
|
||||
private static ViewGroup.MarginLayoutParams edgeToEdgeMargins = null;
|
||||
|
||||
protected final TraditionalT9 tt9;
|
||||
private final int xml;
|
||||
|
||||
|
|
@ -74,28 +76,26 @@ abstract class BaseMainLayout {
|
|||
@RequiresApi(api = Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
||||
protected WindowInsets preventEdgeToEdge(@NonNull View v, @NonNull WindowInsets windowInsets) {
|
||||
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
ViewGroup.MarginLayoutParams layout = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
|
||||
if (layout == null) {
|
||||
return windowInsets;
|
||||
}
|
||||
|
||||
layout.rightMargin = insets.right;
|
||||
layout.bottomMargin = insets.bottom;
|
||||
layout.leftMargin = insets.left;
|
||||
v.setLayoutParams(layout);
|
||||
ViewGroup.MarginLayoutParams marginParams = setMargins(v, insets.right, insets.bottom, insets.left);
|
||||
if (marginParams != null) {
|
||||
edgeToEdgeMargins = marginParams;
|
||||
return WindowInsets.CONSUMED;
|
||||
}
|
||||
|
||||
return windowInsets;
|
||||
}
|
||||
|
||||
protected void preventEdgeToEdge() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM || tt9 == null || tt9.isInputLimited()) {
|
||||
|
||||
/**
|
||||
* Similar to the above method, but reuses the last known margins. Useful for when the Main View
|
||||
* is re-created and it is not yet possible to get the new window insets.
|
||||
*/
|
||||
public void preventEdgeToEdge() {
|
||||
if (view == null || edgeToEdgeMargins == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
return;
|
||||
}
|
||||
|
||||
WindowInsets insets = view != null ? view.getRootWindowInsets() : null;
|
||||
if (insets != null) {
|
||||
preventEdgeToEdge(view, insets);
|
||||
}
|
||||
setMargins(view, edgeToEdgeMargins.rightMargin, edgeToEdgeMargins.bottomMargin, edgeToEdgeMargins.leftMargin);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -129,6 +129,23 @@ abstract class BaseMainLayout {
|
|||
}
|
||||
|
||||
|
||||
private ViewGroup.MarginLayoutParams setMargins(View v, int right, int bottom, int left) {
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ViewGroup.MarginLayoutParams layout = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
|
||||
if (layout != null) {
|
||||
layout.rightMargin = right;
|
||||
layout.bottomMargin = bottom;
|
||||
layout.leftMargin = left;
|
||||
v.setLayoutParams(layout);
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
|
||||
int getHeight(boolean forceRecalculate) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,6 +273,7 @@ class MainLayoutNumpad extends BaseMainLayout {
|
|||
getView();
|
||||
enableClickHandlers();
|
||||
setKeyHeight(defaultKeyHeight);
|
||||
preventEdgeToEdge();
|
||||
setWidth(tt9.getSettings().getWidthPercent(), tt9.getSettings().getAlignment());
|
||||
setKeyColumnWidth(tt9.getSettings().getNumpadFnKeyScale());
|
||||
showLongSpace(
|
||||
|
|
@ -282,7 +283,5 @@ class MainLayoutNumpad extends BaseMainLayout {
|
|||
for (SoftKey key : getKeys()) {
|
||||
key.render();
|
||||
}
|
||||
|
||||
preventEdgeToEdge();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ class MainLayoutTray extends BaseMainLayout {
|
|||
void render() {
|
||||
getView();
|
||||
setSoftKeysVisibility();
|
||||
preventEdgeToEdge();
|
||||
setWidth(tt9.getSettings().getWidthPercent(), tt9.getSettings().getAlignment());
|
||||
enableClickHandlers();
|
||||
for (SoftKey key : getKeys()) {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,10 @@ public class MainView {
|
|||
}
|
||||
|
||||
public void forceCreate() {
|
||||
if (main != null) {
|
||||
Logger.w(getClass().getSimpleName(), "MainView already exists. Re-creating by request.");
|
||||
destroy();
|
||||
}
|
||||
if (!create()) {
|
||||
Logger.w(getClass().getSimpleName(), "Invalid MainView setting. Creating default.");
|
||||
main = new MainLayoutSmall(tt9);
|
||||
|
|
|
|||
|
|
@ -61,8 +61,11 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
}
|
||||
|
||||
|
||||
@Override public void onViewAttachedToWindow(@NonNull View v) { setHeight(height, heightSmall, heightNumpad); }
|
||||
@Override public void onViewDetachedFromWindow(@NonNull View v) {}
|
||||
@Override public void onViewAttachedToWindow(@NonNull View v) {
|
||||
setHeight(height, heightSmall, heightNumpad);
|
||||
main.preventEdgeToEdge();
|
||||
}
|
||||
|
||||
|
||||
public void onOrientationChanged() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue