MoreKeysPanel.java revision 7f8345d59a82a9b1d458b8e55ffd12c2a0d466a7
1/*
2 * Copyright (C) 2011 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.inputmethod.keyboard;
18
19import android.view.View;
20import android.view.ViewGroup;
21
22public interface MoreKeysPanel {
23    public interface Controller {
24        /**
25         * Add the {@link MoreKeysPanel} to the target view.
26         * @param panel the panel to be shown.
27         */
28        public void onShowMoreKeysPanel(final MoreKeysPanel panel);
29
30        /**
31         * Remove the current {@link MoreKeysPanel} from the target view.
32         * @param panel the panel to be dismissed.
33         */
34        public void onDismissMoreKeysPanel(final MoreKeysPanel panel);
35
36        /**
37         * Instructs the parent to cancel the panel (e.g., when entering a different input mode).
38         * @param panel the panel to be canceled.
39         */
40        public void onCancelMoreKeysPanel(final MoreKeysPanel panel);
41    }
42
43    public static final Controller EMPTY_CONTROLLER = new Controller() {
44        @Override
45        public void onShowMoreKeysPanel(final MoreKeysPanel panel) {}
46        @Override
47        public void onDismissMoreKeysPanel(final MoreKeysPanel panel) {}
48        @Override
49        public void onCancelMoreKeysPanel(final MoreKeysPanel panel) {}
50    };
51
52    /**
53     * Initializes the layout and event handling of this {@link MoreKeysPanel} and calls the
54     * controller's onShowMoreKeysPanel to add the panel's container view.
55     *
56     * @param parentView the parent view of this {@link MoreKeysPanel}
57     * @param controller the controller that can dismiss this {@link MoreKeysPanel}
58     * @param pointX x coordinate of this {@link MoreKeysPanel}
59     * @param pointY y coordinate of this {@link MoreKeysPanel}
60     * @param listener the listener that will receive keyboard action from this
61     * {@link MoreKeysPanel}.
62     */
63    // TODO: Currently the MoreKeysPanel is inside a container view that is added to the parent.
64    // Consider the simpler approach of placing the MoreKeysPanel itself into the parent view.
65    public void showMoreKeysPanel(View parentView, Controller controller, int pointX,
66            int pointY, KeyboardActionListener listener);
67
68    /**
69     * Dismisses the more keys panel and calls the controller's onDismissMoreKeysPanel to remove
70     * the panel's container view.
71     */
72    public void dismissMoreKeysPanel();
73
74    /**
75     * Process a move event on the more keys panel.
76     *
77     * @param x translated x coordinate of the touch point
78     * @param y translated y coordinate of the touch point
79     * @param pointerId pointer id touch point
80     * @param eventTime timestamp of touch point
81     */
82    public void onMoveEvent(final int x, final int y, final int pointerId, final long eventTime);
83
84    /**
85     * Process a down event on the more keys panel.
86     *
87     * @param x translated x coordinate of the touch point
88     * @param y translated y coordinate of the touch point
89     * @param pointerId pointer id touch point
90     * @param eventTime timestamp of touch point
91     */
92    public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime);
93
94    /**
95     * Process an up event on the more keys panel.
96     *
97     * @param x translated x coordinate of the touch point
98     * @param y translated y coordinate of the touch point
99     * @param pointerId pointer id touch point
100     * @param eventTime timestamp of touch point
101     */
102    public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime);
103
104    /**
105     * Translate X-coordinate of touch event to the local X-coordinate of this
106     * {@link MoreKeysPanel}.
107     *
108     * @param x the global X-coordinate
109     * @return the local X-coordinate to this {@link MoreKeysPanel}
110     */
111    public int translateX(int x);
112
113    /**
114     * Translate Y-coordinate of touch event to the local Y-coordinate of this
115     * {@link MoreKeysPanel}.
116     *
117     * @param y the global Y-coordinate
118     * @return the local Y-coordinate to this {@link MoreKeysPanel}
119     */
120    public int translateY(int y);
121
122    /**
123     * Show this {@link MoreKeysPanel} in the parent view.
124     *
125     * @param parentView the {@link ViewGroup} that hosts this {@link MoreKeysPanel}.
126     */
127    public void showInParent(ViewGroup parentView);
128
129    /**
130     * Remove this {@link MoreKeysPanel} from the parent view.
131     */
132    public void removeFromParent();
133
134    /**
135     * Return whether the panel is currently being shown.
136     */
137    public boolean isShowingInParent();
138}
139