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

Commit 98e333f5 authored by Karl Rosaen's avatar Karl Rosaen
Browse files

Fix back key and ime behavior for search dialog.

The back key now dismisses the soft keyboard, and then the dialog.

The soft keyboard behavior is improved by having ACTV do the following when 'mDropdownAlwaysShowing' is true:
- touching outside of the drop down doesn't dismiss it
- touching the text field ensures the imei is brought in front of the drop down
parent 4924ae8d
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.app;

import static android.app.SuggestionsAdapter.getColumnString;

import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -26,8 +25,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
@@ -54,14 +53,14 @@ import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

import java.util.ArrayList;
import java.util.WeakHashMap;
@@ -163,7 +162,10 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        setContentView(com.android.internal.R.layout.search_bar);

        theWindow.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
                // taking up the whole window (even when transparent) is less than ideal,
                // but necessary to show the popup window until the window manager supports
                // having windows anchored by their parent but not clipped by them.
                ViewGroup.LayoutParams.FILL_PARENT);
        WindowManager.LayoutParams lp = theWindow.getAttributes();
        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
        theWindow.setAttributes(lp);
@@ -1374,20 +1376,21 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
         */
        @Override
        public boolean onKeyPreIme(int keyCode, KeyEvent event) {
            return mSearchDialog.handleBackKey(keyCode, event);
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                if (mSearchDialog.backToPreviousComponent()) {
                    return true;
                }
                return false; // will dismiss soft keyboard if necessary
            }
            return false;
        }
    }
    
    protected boolean handleBackKey(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            mSearchAutoComplete.dismissDropDown();
            if (backToPreviousComponent()) {
                return true;
            }
            if (!mSearchAutoComplete.isEmpty()) {
                mSearchAutoComplete.clear();
                return true;
            }
            cancel();
            return true;
        }
+45 −1
Original line number Diff line number Diff line
@@ -127,6 +127,8 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
    // The widget is attached to a window when mAttachCount > 0
    private int mAttachCount;

    private AutoCompleteTextView.PassThroughClickListener mPassThroughClickListener;

    public AutoCompleteTextView(Context context) {
        this(context, null);
    }
@@ -186,6 +188,28 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
        setFocusable(true);

        addTextChangedListener(new MyWatcher());

        mPassThroughClickListener = new PassThroughClickListener();
        super.setOnClickListener(mPassThroughClickListener);
    }

    @Override
    public void setOnClickListener(OnClickListener listener) {
        mPassThroughClickListener.mWrapped = listener;
    }

    /**
     * Private hook into the on click event, dispatched from {@link PassThroughClickListener}
     */
    private void onClickImpl() {
        // if drop down should always visible, bring it back in front of the soft
        // keyboard when the user touches the text field
        if (mDropDownAlwaysVisible
                && mPopup.isShowing()
                && mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED) {
            mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            mPopup.update();
        }
    }

    /**
@@ -1050,7 +1074,10 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
            }
            mPopup.setHeight(height);
            mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            mPopup.setOutsideTouchable(true);
            
            // use outside touchable to dismiss drop down when touching outside of it, so
            // only set this if the dropdown is not always visible
            mPopup.setOutsideTouchable(!mDropDownAlwaysVisible);
            mPopup.setTouchInterceptor(new PopupTouchIntercepter());
            mPopup.showAsDropDown(getDropDownAnchorView(),
                    mDropDownHorizontalOffset, mDropDownVerticalOffset);
@@ -1367,4 +1394,21 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
         */
        CharSequence fixText(CharSequence invalidText);
    }

    /**
     * Allows us a private hook into the on click event without preventing users from setting
     * their own click listener.
     */
    private class PassThroughClickListener implements OnClickListener {

        private View.OnClickListener mWrapped;

        /** {@inheritDoc} */
        public void onClick(View v) {
            onClickImpl();

            if (mWrapped != null) mWrapped.onClick(v);
        }
    }

}
+1 −3
Original line number Diff line number Diff line
@@ -22,11 +22,9 @@
    android:id="@+id/search_bar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="200dip"
    android:orientation="vertical"
    android:focusable="true"
    android:descendantFocusability="afterDescendants">
    <!-- android:paddingBottom="200dip"  TODO MUST FIX - it's a hack to get the popup to show -->

    <!-- Outer layout defines the entire search bar at the top of the screen -->
    <LinearLayout