summaryrefslogtreecommitdiff
path: root/library/main
diff options
context:
space:
mode:
authorSandra Alfaro <sandraalfaro@google.com>2021-02-11 16:37:36 -0800
committerSandra Alfaro <sandraalfaro@google.com>2021-02-16 12:03:27 -0800
commit6cb8fa2b94ebd2ea804cc3dc0d4c09e548a2e7b3 (patch)
tree637a9c9b2fc307ae029a04b055c32b915e87949c /library/main
parenta9ad14e4762b93f62316bde10101d33aba80f74e (diff)
downloadsetupwizard-6cb8fa2b94ebd2ea804cc3dc0d4c09e548a2e7b3.tar.gz
Pressing the physical button will have the same behavior as pressing the back button on the toolbar
Bug: 178505894 Test: CarSetupWizardUiUtilsTest Change-Id: I7daa1ebdfbef1e2a1e6343f5ee4d4e2ecb31d663
Diffstat (limited to 'library/main')
-rw-r--r--library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java b/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
index 255f228..9b717a4 100644
--- a/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
+++ b/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
@@ -20,6 +20,7 @@ import android.annotation.CallSuper;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.View;
import androidx.annotation.LayoutRes;
@@ -91,11 +92,7 @@ abstract class BaseSetupWizardActivity extends FragmentActivity {
mCarSetupWizardLayout = findViewById(R.id.car_setup_wizard_layout);
- mCarSetupWizardLayout.setBackButtonListener(v -> {
- if (!handleBackButton()) {
- finish();
- }
- });
+ mCarSetupWizardLayout.setBackButtonListener(v -> handleBackButtonEvent());
mCarSetupWizardLayout.setCloseButtonListener(v-> handleCloseButton());
@@ -246,6 +243,16 @@ abstract class BaseSetupWizardActivity extends FragmentActivity {
}
/**
+ * Method used when back button is pressed, if the back button wasn't handled by the activity
+ * finish() will be called.
+ */
+ private void handleBackButtonEvent() {
+ if (!handleBackButton()) {
+ finish();
+ }
+ }
+
+ /**
* Method to be overwritten by subclasses wanting to implement their own back behavior.
* Default behavior is to pop a fragment off of the backstack if one exists, otherwise call
* finish()
@@ -256,6 +263,16 @@ abstract class BaseSetupWizardActivity extends FragmentActivity {
return popBackStackImmediate();
}
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
+ && event.getAction() == KeyEvent.ACTION_UP) {
+ handleBackButtonEvent();
+ return true;
+ }
+ return super.dispatchKeyEvent(event);
+ }
+
/**
* Method to be overwritten by subclasses wanting to implement their own close behavior.
* Default behavior is finishAction.