Add inset detection and passthrough

This commit is contained in:
Pieter Vander Vennet 2025-07-14 00:36:31 +02:00
parent ea302c23c4
commit eb3afb0057
5 changed files with 22 additions and 5 deletions

View file

@ -7,7 +7,7 @@ android {
applicationId "org.mapcomplete"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 5
versionCode 9
versionName "debug"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
@ -53,6 +53,8 @@ repositories {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.core:core:1.16.0'
implementation 'androidx.core:core-ktx:1.16.0'
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"

View file

@ -32,7 +32,7 @@ public class Databridge extends Plugin {
}
JSObject ret = new JSObject();
ret.put("value", answer);
Log.i("databridge", "Resolving call");
Log.i("databridge", "Resolving call for "+call+" with "+answer);
call.resolve(ret);
}

View file

@ -3,14 +3,18 @@ package org.mapcomplete;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.Window;
import android.view.WindowInsets;
import android.window.OnBackInvokedDispatcher;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.WindowCompat;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.JSObject;
@ -63,7 +67,17 @@ public class MainActivity extends BridgeActivity {
});
super.onCreate(savedInstanceState);
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
Databridge.addResponder("insets", (responder) -> {
var view = getWindow().getDecorView();
var insets = view.getRootWindowInsets();
var topInsetPxSize= insets.getInsetsIgnoringVisibility(WindowInsets.Type.statusBars()).top;
var bottomInsetPxSize= insets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars()).bottom;
var json = "{ \"top\": "+topInsetPxSize+", \"bottom\":"+bottomInsetPxSize+"}";
Log.i("insets","Inset sizes are:"+topInsetPxSize+" bottom:"+ bottomInsetPxSize);
Databridge.sendAnswerTo(responder, json);
});
getOnBackInvokedDispatcher().registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_OVERLAY,
() -> {
@ -75,6 +89,7 @@ public class MainActivity extends BridgeActivity {
);
}
private boolean hasGeolocationPermission() {
return ContextCompat.checkSelfPermission(
getApplicationContext(),

View file

@ -1,3 +1,3 @@
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
project(':capacitor-android').projectDir = new File('@capacitor/android/capacitor')