blob: 18a464a5c8c79ca8920ca02dc34c5d6687d4062e [file] [log] [blame]
The Android Open Source Projectb28e1b72009-03-02 22:54:41 -08001/*
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
17package com.android.launcher;
18
19import android.widget.AutoCompleteTextView;
20import android.content.Context;
21import android.util.AttributeSet;
22import android.graphics.Rect;
23import android.view.WindowManager;
24import android.view.inputmethod.InputMethodManager;
25import 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 */
34public 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}