1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package sk.baka.ambient.views.gesturelist.keypad;
20
21 import android.view.KeyEvent;
22 import sk.baka.ambient.views.KeyEventHandler;
23 import sk.baka.ambient.views.gesturelist.GesturesListView;
24
25 /***
26 * Handles the key events.
27 *
28 * @author Martin Vysny
29 */
30 public abstract class AbstractKeypadHandler extends KeyEventHandler {
31 /***
32 * The owner instance.
33 */
34 protected final GesturesListView owner;
35
36 /***
37 * Creates new handler.
38 *
39 * @param owner
40 * owner list view
41 */
42 public AbstractKeypadHandler(final GesturesListView owner) {
43 this.owner = owner;
44 }
45
46 /***
47 * Checks if this handler is activated by given key press.
48 *
49 * @param keyCode
50 * the key code
51 * @param event
52 * the event.
53 * @return <code>true</code> if this handler should be activated,
54 * <code>false</code> otherwise.
55 */
56 public abstract boolean isActivatedByKey(final int keyCode,
57 final KeyEvent event);
58
59 /***
60 * Starts this key handler. The handler should initialize and start
61 * listening for keys.
62 */
63 public abstract void start();
64
65 /***
66 * Stops this key handler. The handler should clean up. No more keys will be
67 * received unless {@link #start()} is invoked again.
68 */
69 public abstract void stop();
70
71 /***
72 * Checks if this handler is started.
73 *
74 * @return <code>true</code> if started, <code>false</code> otherwise.
75 */
76 public abstract boolean isStarted();
77
78 /***
79 * Invoked when the selection is changed in the underlying list view.
80 */
81 public void selectionChanged() {
82 }
83 }