android/source/build.gradle                                           |    2 
 android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java  |   86 
+++++-----
 android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java |   25 +-
 3 files changed, 66 insertions(+), 47 deletions(-)

New commits:
commit 354c70556b5656c586adf4c8cc0521687bd77e22
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Jul 9 14:21:08 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Jul 10 07:25:30 2025 +0200

    android: Port from deprecated ComponentActivity.onBackPressed (II)
    
    Port LibreOfficeUIActivity from overriding the deprecated
    androidx.ComponentActivity.onBackPressed method [1]
    and register a androidx.activity.OnBackPressedCallback [2].
    
    Overriding the deprecated API was already triggering a warning
    and that was turned into a build/lint error in a WIP branch updating the
    compileSdkVersion and targetSdkVersion to 36.
    
    Interaction when using the back button (or gesture)
    remains the same after enabling experimental editing option
    and clicking the "+" button to display the options to create
    new filesin a quick test (with an additional
    local revert of commit 9d1e76f7da12353afc3d9479d3b2ecddbb2a71e6
    to prevent a deadlock when opening documents that is unrelated
    to this change here).
    
    [1] 
https://developer.android.com/reference/androidx/activity/ComponentActivity#onBackPressed()
    [2] 
https://developer.android.com/reference/androidx/activity/OnBackPressedCallback
    
    Change-Id: Ie5e9f3be7321d40f43ebf584db367432afb70577
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187573
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git 
a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java 
b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 3f93d815af27..69bf430dd6b0 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -22,6 +22,8 @@ import android.graphics.drawable.Icon;
 import android.net.Uri;
 import android.os.Bundle;
 import com.google.android.material.floatingactionbutton.FloatingActionButton;
+
+import androidx.activity.OnBackPressedCallback;
 import androidx.core.app.ActivityCompat;
 import androidx.core.content.ContextCompat;
 import androidx.core.view.ViewCompat;
@@ -142,6 +144,20 @@ public class LibreOfficeUIActivity extends 
AppCompatActivity implements View.OnC
         createUI();
         fabOpenAnimation = AnimationUtils.loadAnimation(this, R.anim.fab_open);
         fabCloseAnimation = AnimationUtils.loadAnimation(this, 
R.anim.fab_close);
+
+        getOnBackPressedDispatcher().addCallback(new 
OnBackPressedCallback(true) {
+            @Override
+            public void handleOnBackPressed() {
+                if (isFabMenuOpen) {
+                    collapseFabMenu();
+                    return;
+                } else {
+                    setEnabled(false);
+                    getOnBackPressedDispatcher().onBackPressed();
+                    setEnabled(true);
+                }
+            }
+        });
     }
 
     @Override
@@ -234,15 +250,6 @@ public class LibreOfficeUIActivity extends 
AppCompatActivity implements View.OnC
         isFabMenuOpen = false;
     }
 
-    @Override
-    public void onBackPressed() {
-        if (isFabMenuOpen) {
-            collapseFabMenu();
-        } else {
-            super.onBackPressed();
-        }
-    }
-
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent 
data) {
         super.onActivityResult(requestCode, resultCode, data);
commit 9fa0ea06bc4f6be647ef4ac4d5bc1830bfc93ec4
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Jul 9 13:54:23 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Jul 10 07:25:25 2025 +0200

    android: Port from deprecated ComponentActivity.onBackPressed (I)
    
    Port LibreOfficeMainActivity from overriding the deprecated
    androidx.ComponentActivity.onBackPressed method [1]
    and register a androidx.activity.OnBackPressedCallback [2].
    
    Overriding the deprecated API was already triggering warning
    
        
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java:511:
 warning: [deprecation] onBackPressed() in ComponentActivity has been deprecated
            public void onBackPressed() {
                        ^
    and that was turned into a build/lint error in a WIP branch updating the
    compileSdkVersion and targetSdkVersion to 36:
    
        
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java:511:
 Error: onBackPressed is no longer called for back gestures; migrate to 
AndroidX's backward compatible OnBackPressedDispatcher [GestureBackNavigation]
            public void onBackPressed() {
                        ~~~~~~~~~~~~~
    
    Interaction when using the back button (or gesture)
    remains as before in a quick test (with an additional
    local revert of commit 9d1e76f7da12353afc3d9479d3b2ecddbb2a71e6
    to prevent a deadlock when opening documents that is unrelated
    to this change here).
    
    [1] 
https://developer.android.com/reference/androidx/activity/ComponentActivity#onBackPressed()
    [2] 
https://developer.android.com/reference/androidx/activity/OnBackPressedCallback
    
    Change-Id: Id5bde62fede7e0550a86bd0ba9bd1535a84003dc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187572
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git 
a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java 
b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 505c886c4403..63e7e8a314f4 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -14,6 +14,8 @@ import android.os.Bundle;
 import android.provider.DocumentsContract;
 import com.google.android.material.bottomsheet.BottomSheetBehavior;
 import com.google.android.material.snackbar.Snackbar;
+
+import androidx.activity.OnBackPressedCallback;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.widget.Toolbar;
@@ -259,6 +261,53 @@ public class LibreOfficeMainActivity extends 
AppCompatActivity implements Shared
         bottomToolbarSheetBehavior.setHideable(true);
         toolbarColorPickerBottomSheetBehavior.setHideable(true);
         toolbarBackColorPickerBottomSheetBehavior.setHideable(true);
+
+        getOnBackPressedDispatcher().addCallback(new 
OnBackPressedCallback(true) {
+            private void forwardBackPress()
+            {
+                setEnabled(false);
+                
LibreOfficeMainActivity.this.getOnBackPressedDispatcher().onBackPressed();
+                setEnabled(true);
+            }
+
+            @Override
+            public void handleOnBackPressed() {
+                if (!isDocumentChanged) {
+                    forwardBackPress();
+                    return;
+                }
+
+
+                DialogInterface.OnClickListener dialogClickListener = new 
DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        switch (which){
+                            case DialogInterface.BUTTON_POSITIVE:
+                                mTileProvider.saveDocument();
+                                isDocumentChanged=false;
+                                forwardBackPress();
+                                break;
+                            case DialogInterface.BUTTON_NEGATIVE:
+                                //CANCEL
+                                break;
+                            case DialogInterface.BUTTON_NEUTRAL:
+                                //NO
+                                isDocumentChanged=false;
+                                forwardBackPress();
+                                break;
+                        }
+                    }
+                };
+
+                AlertDialog.Builder builder = new 
AlertDialog.Builder(LibreOfficeMainActivity.this);
+                builder.setMessage(R.string.save_alert_dialog_title)
+                    .setPositiveButton(R.string.save_document, 
dialogClickListener)
+                    .setNegativeButton(R.string.action_cancel, 
dialogClickListener)
+                    .setNeutralButton(R.string.no_save_document, 
dialogClickListener)
+                    .show();
+
+            }
+        });
     }
 
     private void updatePreferences() {
@@ -507,43 +556,6 @@ public class LibreOfficeMainActivity extends 
AppCompatActivity implements Shared
             }
         }
     }
-    @Override
-    public void onBackPressed() {
-        if (!isDocumentChanged) {
-            super.onBackPressed();
-            return;
-        }
-
-
-        DialogInterface.OnClickListener dialogClickListener = new 
DialogInterface.OnClickListener() {
-            @Override
-            public void onClick(DialogInterface dialog, int which) {
-                switch (which){
-                    case DialogInterface.BUTTON_POSITIVE:
-                        mTileProvider.saveDocument();
-                        isDocumentChanged=false;
-                        onBackPressed();
-                        break;
-                    case DialogInterface.BUTTON_NEGATIVE:
-                        //CANCEL
-                        break;
-                    case DialogInterface.BUTTON_NEUTRAL:
-                        //NO
-                        isDocumentChanged=false;
-                        onBackPressed();
-                        break;
-                }
-            }
-        };
-
-        AlertDialog.Builder builder = new AlertDialog.Builder(this);
-        builder.setMessage(R.string.save_alert_dialog_title)
-                .setPositiveButton(R.string.save_document, dialogClickListener)
-                .setNegativeButton(R.string.action_cancel, dialogClickListener)
-                .setNeutralButton(R.string.no_save_document, 
dialogClickListener)
-                .show();
-
-    }
 
     public List<DocumentPartView> getDocumentPartView() {
         return mDocumentPartView;
commit 622b70aa5cf7d0e50d9c5280583b83a89841ebc7
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Jul 9 12:01:17 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Jul 10 07:25:19 2025 +0200

    android: Update androidx.constraintlayout:constraintlayout to 2.2.1
    
    Change-Id: I810185a7004a7d66626654a30cb4123a1b67b875
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187571
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/android/source/build.gradle b/android/source/build.gradle
index 2e580f4981a4..9dcb83ce2f2a 100644
--- a/android/source/build.gradle
+++ b/android/source/build.gradle
@@ -33,7 +33,7 @@ dependencies {
             "unoloader.jar"
     ])
     implementation 'com.google.android.material:material:1.12.0'
-    implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
+    implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
     implementation 'androidx.preference:preference:1.2.1'
 }
 

Reply via email to