The Android Open Source Project | b28e1b7 | 2009-03-02 22:54:41 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher; |
| 18 | |
| 19 | import android.widget.AutoCompleteTextView; |
| 20 | import android.content.Context; |
| 21 | import android.util.AttributeSet; |
| 22 | import android.graphics.Rect; |
| 23 | import android.view.WindowManager; |
| 24 | import android.view.inputmethod.InputMethodManager; |
| 25 | import android.app.Activity; |
| 26 | |
| 27 | /** |
| 28 | * This class is not for the faint of heart. Home works in the pan & scan |
| 29 | * soft input mode. However, this mode gets rid of the soft keyboard on rotation, |
| 30 | * which is a probelm when the Search widget has focus. This special class |
| 31 | * changes Home's soft input method temporarily as long as the Search widget holds |
| 32 | * the focus. This way, the soft keyboard remains after rotation. |
| 33 | */ |
| 34 | public class SearchAutoCompleteTextView extends AutoCompleteTextView { |
| 35 | public SearchAutoCompleteTextView(Context context) { |
| 36 | super(context); |
| 37 | } |
| 38 | |
| 39 | public SearchAutoCompleteTextView(Context context, AttributeSet attrs) { |
| 40 | super(context, attrs); |
| 41 | } |
| 42 | |
| 43 | public SearchAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) { |
| 44 | super(context, attrs, defStyle); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
| 49 | super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
| 50 | |
| 51 | final WindowManager.LayoutParams lp = ((Activity) getContext()).getWindow().getAttributes(); |
| 52 | if (gainFocus) { |
| 53 | lp.softInputMode = |
| 54 | (lp.softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) | |
| 55 | WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED; |
| 56 | } else { |
| 57 | //noinspection PointlessBitwiseExpression |
| 58 | lp.softInputMode = |
| 59 | (lp.softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) | |
| 60 | WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED; |
| 61 | |
| 62 | // Hide the soft keyboard when the search widget loses the focus |
| 63 | InputMethodManager.peekInstance().hideSoftInputFromWindow(getWindowToken(), 0); |
| 64 | } |
| 65 | |
| 66 | final WindowManager manager = (WindowManager) |
| 67 | getContext().getSystemService(Context.WINDOW_SERVICE); |
| 68 | manager.updateViewLayout(getRootView(), lp); |
| 69 | } |
| 70 | } |