|
28 | 28 | import android.widget.CompoundButton; |
29 | 29 | import android.widget.LinearLayout; |
30 | 30 |
|
31 | | -import androidx.activity.OnBackPressedCallback; |
32 | 31 | import androidx.annotation.NonNull; |
33 | 32 | import androidx.annotation.Nullable; |
34 | 33 | import androidx.annotation.VisibleForTesting; |
@@ -197,26 +196,6 @@ public void onClick(View view) { |
197 | 196 | } |
198 | 197 |
|
199 | 198 | addMenuProvider(this, this); |
200 | | - |
201 | | - // Set up back button handling |
202 | | - getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { |
203 | | - @Override |
204 | | - public void handleOnBackPressed() { |
205 | | - if (fullscreen) { |
206 | | - leaveFullscreen(); |
207 | | - return; |
208 | | - } |
209 | | - |
210 | | - // If document is currently displayed and was opened internally, go back to landing |
211 | | - if (documentContainer.getVisibility() == View.VISIBLE && documentOpenedInternally) { |
212 | | - showLandingScreen(); |
213 | | - } else { |
214 | | - // For external launches or when already on landing screen, use default behavior (close app) |
215 | | - setEnabled(false); |
216 | | - getOnBackPressedDispatcher().onBackPressed(); |
217 | | - } |
218 | | - } |
219 | | - }); |
220 | 199 | } |
221 | 200 |
|
222 | 201 | @Override |
@@ -385,6 +364,18 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent) |
385 | 364 | } |
386 | 365 |
|
387 | 366 | public void loadUri(Uri uri) { |
| 367 | + loadUriInternal(uri, false); |
| 368 | + } |
| 369 | + |
| 370 | + public void loadUriFromInternalNavigation(Uri uri) { |
| 371 | + loadUriInternal(uri, true); |
| 372 | + } |
| 373 | + |
| 374 | + private void loadUriInternal(Uri uri, boolean isInternal) { |
| 375 | + if (isInternal) { |
| 376 | + documentOpenedInternally = true; |
| 377 | + } |
| 378 | + |
388 | 379 | lastSaveUri = null; |
389 | 380 | lastUri = uri; |
390 | 381 |
|
@@ -581,6 +572,22 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { |
581 | 572 | return super.onKeyDown(keyCode, event); |
582 | 573 | } |
583 | 574 |
|
| 575 | + @Override |
| 576 | + public void onBackPressed() { |
| 577 | + if (fullscreen) { |
| 578 | + leaveFullscreen(); |
| 579 | + return; |
| 580 | + } |
| 581 | + |
| 582 | + // If document is currently displayed and was opened internally, go back to landing |
| 583 | + if (documentContainer.getVisibility() == View.VISIBLE && documentOpenedInternally) { |
| 584 | + showLandingScreen(); |
| 585 | + } else { |
| 586 | + // For external launches or when already on landing screen, use default behavior (close app) |
| 587 | + super.onBackPressed(); |
| 588 | + } |
| 589 | + } |
| 590 | + |
584 | 591 | public void findDocument() { |
585 | 592 | final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); |
586 | 593 | intent.addCategory(Intent.CATEGORY_OPENABLE); |
|
0 commit comments