2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.launcher;
19 import android.widget.AutoCompleteTextView;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.util.AttributeSet;
23 import android.graphics.Rect;
24 import android.view.WindowManager;
25 import android.view.inputmethod.InputMethodManager;
26 import android.app.Activity;
29 * This class is not for the faint of heart. Home works in the pan & scan
30 * soft input mode. However, this mode gets rid of the soft keyboard on rotation,
31 * which is a probelm when the Search widget has focus. This special class
32 * changes Home's soft input method temporarily as long as the Search widget holds
33 * the focus. This way, the soft keyboard remains after rotation.
35 public class SearchAutoCompleteTextView extends AutoCompleteTextView {
36 private boolean mShowKeyboard;
38 public SearchAutoCompleteTextView(Context context) {
42 public SearchAutoCompleteTextView(Context context, AttributeSet attrs) {
43 super(context, attrs);
46 public SearchAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) {
47 super(context, attrs, defStyle);
51 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
52 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
54 final WindowManager.LayoutParams lp = ((Activity) getContext()).getWindow().getAttributes();
57 (lp.softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) |
58 WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED;
60 //noinspection PointlessBitwiseExpression
62 (lp.softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) |
63 WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;
65 // Hide the soft keyboard when the search widget loses the focus
66 InputMethodManager.peekInstance().hideSoftInputFromWindow(getWindowToken(), 0);
69 final WindowManager manager = (WindowManager)
70 getContext().getSystemService(Context.WINDOW_SERVICE);
71 manager.updateViewLayout(getRootView(), lp);
74 if (getContext().getResources().getConfiguration().hardKeyboardHidden ==
75 Configuration.HARDKEYBOARDHIDDEN_YES) {
76 InputMethodManager inputManager = (InputMethodManager)
77 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
78 inputManager.showSoftInput(this, 0);
80 mShowKeyboard = false;
85 public void onWindowFocusChanged(boolean hasWindowFocus) {
86 super.onWindowFocusChanged(hasWindowFocus);
87 // See Workspace#focusOnSearch()
88 setFocusableInTouchMode(false);
91 void showKeyboardOnNextFocus() {