From d9ba201f592d7112f8c41654dfdc05dd182a82bb Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Mon, 11 Jul 2016 16:25:33 -0700 Subject: [PATCH] Trapping backspace at EditText level to prevent popping Docs. When the EditText is empty, pressing backspace on soft/hardware keyboard will call on the EditText's OnKeyListener. Since we don't handle backspace, it will then bubble up to Activity-level, which will then pop the document stack due to the feature of using backspace as navigation. This will trap the call correctly if the EditText is empty. Bug: 30066261 Change-Id: I231507b9469bfa52478872491f1d2713a1ac58ba --- .../src/com/android/documentsui/SaveFragment.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/DocumentsUI/src/com/android/documentsui/SaveFragment.java b/packages/DocumentsUI/src/com/android/documentsui/SaveFragment.java index d830c61f30e71..a37590d2e0a6c 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/SaveFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/SaveFragment.java @@ -22,6 +22,7 @@ import android.app.FragmentTransaction; import android.content.Context; import android.os.Bundle; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -91,6 +92,14 @@ public class SaveFragment extends Fragment { return false; } + // Returning false in this method will bubble the event up to + // {@link BaseActivity#onKeyDown}. In order to prevent backspace popping + // documents once the textView is empty, we are going to trap it here. + if (keyCode == KeyEvent.KEYCODE_DEL + && TextUtils.isEmpty(mDisplayName.getText())) { + return true; + } + if (keyCode == KeyEvent.KEYCODE_ENTER && mSave.isEnabled()) { performSave(); return true;