Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 019d8152 authored by Johannes Gallmann's avatar Johannes Gallmann Committed by Android (Google) Code Review
Browse files

Merge "Migrate PrintActivity to enableOnBackInvokedCallback=true" into main

parents 0e5c32c1 57dd1166
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@
            android:configChanges="mnc|mnc|touchscreen|navigation|screenLayout|screenSize|smallestScreenSize|orientation|locale|keyboard|keyboardHidden|fontScale|uiMode|layoutDirection|density"
            android:permission="android.permission.BIND_PRINT_SPOOLER_SERVICE"
            android:theme="@style/Theme.PrintActivity"
            android:enableOnBackInvokedCallback="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.print.PRINT_DIALOG" />
+13 −6
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.window.OnBackInvokedDispatcher;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -323,6 +324,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
                });

        getLoaderManager().initLoader(LOADER_ID_ENABLED_PRINT_SERVICES, null, this);
        getWindow().getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
                OnBackInvokedDispatcher.PRIORITY_DEFAULT, this::onBackInvoked);
    }

    private void onConnectedToPrintSpooler(final IBinder documentAdapter) {
@@ -481,15 +484,19 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat

        if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE)
                && event.isTracking() && !event.isCanceled()) {
            onBackInvoked();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    private void onBackInvoked() {
        if (mPrintPreviewController != null && mPrintPreviewController.isOptionsOpened()
                && !hasErrors()) {
            mPrintPreviewController.closeOptions();
        } else {
            cancelPrint();
        }
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override