2 * Copyright (C) 2007-2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
17 package android.inputmethodservice;
19 import android.app.Dialog;
20 import android.content.Context;
21 import android.content.pm.ActivityInfo;
22 import android.os.IBinder;
23 import android.view.Gravity;
24 import android.view.KeyEvent;
25 import android.view.WindowManager;
28 * A SoftInputWindow is a Dialog that is intended to be used for a top-level input
29 * method window. It will be displayed along the edge of the screen, moving
30 * the application user interface away from it so that the focused item is
33 class SoftInputWindow extends Dialog {
34 final KeyEvent.DispatcherState mDispatcherState;
36 public void setToken(IBinder token) {
37 WindowManager.LayoutParams lp = getWindow().getAttributes();
39 getWindow().setAttributes(lp);
43 * Create a DockWindow that uses a custom style.
45 * @param context The Context in which the DockWindow should run. In
46 * particular, it uses the window manager and theme from this context
48 * @param theme A style resource describing the theme to use for the window.
49 * See <a href="{@docRoot}reference/available-resources.html#stylesandthemes">Style
50 * and Theme Resources</a> for more information about defining and
51 * using styles. This theme is applied on top of the current theme in
52 * <var>context</var>. If 0, the default dialog theme will be used.
54 public SoftInputWindow(Context context, int theme,
55 KeyEvent.DispatcherState dispatcherState) {
56 super(context, theme);
57 mDispatcherState = dispatcherState;
62 public void onWindowFocusChanged(boolean hasFocus) {
63 super.onWindowFocusChanged(hasFocus);
64 mDispatcherState.reset();
68 * Get the size of the DockWindow.
70 * @return If the DockWindow sticks to the top or bottom of the screen, the
71 * return value is the height of the DockWindow, and its width is
72 * equal to the width of the screen; If the DockWindow sticks to the
73 * left or right of the screen, the return value is the width of the
74 * DockWindow, and its height is equal to the height of the screen.
76 public int getSize() {
77 WindowManager.LayoutParams lp = getWindow().getAttributes();
79 if (lp.gravity == Gravity.TOP || lp.gravity == Gravity.BOTTOM) {
87 * Set the size of the DockWindow.
89 * @param size If the DockWindow sticks to the top or bottom of the screen,
90 * <var>size</var> is the height of the DockWindow, and its width is
91 * equal to the width of the screen; If the DockWindow sticks to the
92 * left or right of the screen, <var>size</var> is the width of the
93 * DockWindow, and its height is equal to the height of the screen.
95 public void setSize(int size) {
96 WindowManager.LayoutParams lp = getWindow().getAttributes();
98 if (lp.gravity == Gravity.TOP || lp.gravity == Gravity.BOTTOM) {
105 getWindow().setAttributes(lp);
109 * Set which boundary of the screen the DockWindow sticks to.
111 * @param gravity The boundary of the screen to stick. See {#link
112 * android.view.Gravity.LEFT}, {#link android.view.Gravity.TOP},
113 * {#link android.view.Gravity.BOTTOM}, {#link
114 * android.view.Gravity.RIGHT}.
116 public void setGravity(int gravity) {
117 WindowManager.LayoutParams lp = getWindow().getAttributes();
119 boolean oldIsVertical = (lp.gravity == Gravity.TOP || lp.gravity == Gravity.BOTTOM);
121 lp.gravity = gravity;
123 boolean newIsVertical = (lp.gravity == Gravity.TOP || lp.gravity == Gravity.BOTTOM);
125 if (oldIsVertical != newIsVertical) {
127 lp.width = lp.height;
129 getWindow().setAttributes(lp);
133 private void initDockWindow() {
134 WindowManager.LayoutParams lp = getWindow().getAttributes();
136 lp.type = WindowManager.LayoutParams.TYPE_INPUT_METHOD;
137 lp.setTitle("InputMethod");
139 lp.gravity = Gravity.BOTTOM;
141 // Let the input method window's orientation follow sensor based rotation
142 // Turn this off for now, it is very problematic.
143 //lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
145 getWindow().setAttributes(lp);
146 getWindow().setFlags(
147 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
148 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
149 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
150 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
151 WindowManager.LayoutParams.FLAG_DIM_BEHIND);